Reputation
9,476
Next privilege 10,000 Rep.
Access moderator tools
Badges
1 24 41
Newest
 Nice Answer
Impact
~435k people reached

Dec
1
answered How do you keep track of a requirements document on an agile team?
Nov
29
answered What to do when a project is too difficult to continue developing?
Nov
27
awarded  Good Answer
Nov
27
comment What should be allowed inside getters and setters?
To avoid having too many comments here, I'll take this conversation into this chat and address your comment there.
Nov
27
comment What should be allowed inside getters and setters?
I've created a Chat Session to allow these comments to continue as needed.
Nov
27
comment What should be allowed inside getters and setters?
@methodman Yes, I agree that a public field is wrong, however a public property can be useful. That property can be used to provide a place for validation or events related to the setting or returning of the data, depending on the specific requirement at the time. Getters and setters themselves aren't wrong per-se. How and when they are used or abused on the other hand can be seen as poor in terms of design and maintainability depending on the circumstances. :)
Nov
27
comment What should be allowed inside getters and setters?
I think you're missing the point of the article, which suggests using getters/setters sparingly and to avoid exposing class data unless necessary. This IMHO is a sensible design principle which should be applied deliberately by the developer. In terms of creating properties on a class, you could simply expose a variable, but this makes it harder to provide validation when the variable is set, or to draw the value from an alternate source when "got", essentially violating encapsulation, and potentially locking you into a difficult to maintain interface design.
Nov
26
comment What should be allowed inside getters and setters?
@glenatron You miss the point that I'm writing about. Side effects within properties aren't always predictable. When you set a property Value, you expect that same value to be returned. When you call a function that may use a value, then you assume the output won't necessarily be that value itself.
Nov
26
comment What should be allowed inside getters and setters?
@MarkByers You may wish to validate input of floating point values by applying a rule that only a fixed number of decimal places is allowed. In that circumstance, you could either raise an exception if too many decimal places are input, or you could simply round the input value. This may be preferable to raising an exception. I agree though that the sentence you've quoted probably needs to be modified. I'll think about this and edit. :)
Nov
26
awarded  Nice Answer
Nov
25
revised Is there a term for “Use procedures that execute a single task”?
grammatical correction
Nov
25
comment What should be allowed inside getters and setters?
There are a couple of problems with this. Arbitrarily setting a value creates a deliberate and unclear side-effect. Also, it doesn't allow the calling code to receive feedback which could be used to better deal with illegal data. This is particularly important with values at the UI level. To be fair though, one exception I just thought of could be if allowing multiple date formats as an input, while storing the date in a standard date/time format. One could at a stretch argue that this particular "side effect" is a normalization of the data at validation, provided the input data is legal.
Nov
25
answered Is there a term for “Use procedures that execute a single task”?
Nov
25
answered What should be allowed inside getters and setters?
Nov
24
revised What is the best way to evaluate new programmers?
modified a URL - to avoid a future dead link
Nov
24
revised Should SpecFlow be used with BDD as a solo developer?
corrected an aging URL - to avoid a dead link in the future ;)
Nov
15
awarded  Nice Question
Nov
1
awarded  Popular Question
Oct
21
awarded  Yearling
Oct
16
awarded  Necromancer