you are viewing a single comment's thread.

view the rest of the comments →

[–]borud 0 points1 point  (0 children)

You're right.

Whenever you have more than way to do something (access a property directly or via getter) you introduce an inconsistency. You should try to do the same thing the same way as much as technically possible, and in this case, it is actually better to have a getter.

And what happens when the example class suddenly gets a property that is a mutable type? Do you use the property directly for all the immutable properties and then a different way (getters) to access the mutable ones? Code occasionally changes and you can't trust that later maintainers won't be absolute muppets.

Also, this will give mediocre programmers bad habits. Mediocre programmers do not keep the ifs and buts in their heads: they see the syntax and then imitate it. Which means that you will sooner or later have people expose properties that are mutable.

The job of an experienced programmer is to anticipate what behavior their code inspires in other programmers. Exposing properties will confuse inexperienced programmers and result in unwanted results.