On Tuesday, 11 December 2018 at 14:00:10 UTC, dayllenger wrote:
On Tuesday, 11 December 2018 at 13:42:03 UTC, Guillaume Piolat
wrote:
One could say getters and particularly setters don't really
deserve a nicer way to write them. It's a code stink, it
deserve a long ugly name. (10 years ago I would be in the
other camp)
Can you please explain it in more detail? I never read such
about getters and setters.
Tell, don't ask: https://martinfowler.com/bliki/TellDontAsk.html
Getters and setters break encapsulation - the client knows way
too much about your struct/class. Whatever you were going to do
with the data you got from the object, move it into a member
function of that object's type.
Setters are like that as well, but worse since mutable state is
the root of all evil. Personally, I cringe whenever I have to use
`auto` instead of `const` for a variable declaration.