12 Matching Annotations
- Jun 2023
-
stackoverflow.com stackoverflow.com
-
Are protected members/fields really that bad? No. They are way, way worse. As soon as a member is more accessible than private, you are making guarantees to other classes about how that member will behave. Since a field is totally uncontrolled, putting it "out in the wild" opens your class and classes that inherit from or interact with your class to higher bug risk. There is no way to know when a field changes, no way to control who or what changes it. If now, or at some point in the future, any of your code ever depends on a field some certain value, you now have to add validity checks and fallback logic in case it's not the expected value - every place you use it. That's a huge amount of wasted effort when you could've just made it a damn property instead ;) The best way to share information with deriving classes is the read-only property: protected object MyProperty { get; } If you absolutely have to make it read/write, don't. If you really, really have to make it read-write, rethink your design. If you still need it to be read-write, apologize to your colleagues and don't do it again :) A lot of developers believe - and will tell you - that this is overly strict. And it's true that you can get by just fine without being this strict. But taking this approach will help you go from just getting by to remarkably robust software. You'll spend far less time fixing bugs.
In other words, make the member variable itself private, but can be abstracted (and access provided) via public methods/properties
-
-
stackoverflow.com stackoverflow.com
-
I'm not saying never mark methods private. I'm saying the better rule of thumb is to "make methods protected unless there's a good reason not to".
-
Marking methods protected by default is a mitigation for one of the major issues in modern SW development: failure of imagination.
-
The old wisdom "mark it private unless you have a good reason not to" made sense in days when it was written, before open source dominated the developer library space and VCS/dependency mgmt. became hyper collaborative thanks to Github, Maven, etc. Back then there was also money to be made by constraining the way(s) in which a library could be utilized. I spent probably the first 8 or 9 years of my career strictly adhering to this "best practice". Today, I believe it to be bad advice. Sometimes there's a reasonable argument to mark a method private, or a class final but it's exceedingly rare, and even then it's probably not improving anything.
Tags
- you can't know for sure
- what does this actually mean?
- reasonable defaults
- member visibility: make it private unless you have a good reason not to
- failure of imagination
- software development
- please elaborate
- bad advice
- member visibility: make it protected unless you have a good reason not to
- extensibility
- can't predict the future
- rule of thumb
- never say never
Annotators
URL
-
- Aug 2021
-
-
If you dig into the details, you will see that the TypeScript team take breaking changes very seriously and with consideration.
-
I think the TS team generally tries to minimize breaking changes from version to version and don't do so unless there is a good reason.
-
- Oct 2020
-
-
Of all the compile-to-languages, the one that strikes me as having the least merit is JSX. It's basically a ton of added complexity for the sake of what boils down to syntax. There are no real gains in terms of language semantics in JSX.
-
I agree that "it feels gross" is a bad reason. "not paving a bad cowpath" is a much better reason.
-
-
www.python.org www.python.org
-
Because the code in question predates the introduction of the guideline and there is no other reason to be modifying that code.
Tags
Annotators
URL
-
- Apr 2020
-
www.kickstarter.com www.kickstarter.com
-
We wondered - do voters carefully consider the political issues and then objectively study each candidate’s platform, or do they mainly go with from-the-gut “tribal” feelings?
-
- Dec 2019
-
unixwiz.net unixwiz.net
-
I would rather you vote against my position because you had an opposing view than vote with my position because you flipped a coin.
-
I believe that mere lists of "vote yes" or "vote no" are not very helpful except for sheep: it's important to know why one is urged to vote in any given direction.
-