Getters and setters
Posted Feb 6, 2011 23:30 UTC (Sun) by
man_ls (subscriber, #15091)
In reply to:
C for anything by ncm
Parent article:
LCA: Lessons from 30 years of Sendmail
You have keep the Java monkeys away, though, or you'll spend your life writing Get and Set functions, and calls to them.
That comment is a bit cruel, but it's right on target. I have been wondering for the last 5 years what all those getters and setters were buying us. On one hand you were supposed to use them instead of public attributes because you could change the way to access the particular attribute later on. On the other, you were not supposed to do weird things in getters or setters since it might be considered as a bad practice. Even simple encapsulation of another object can be frowned upon in certain circles, and it certainly does not help understand the code.
I turned to public attributes a few years ago and never regretted it. You know, I'm not against the occasional access method, and separating methods with side effects from methods that return values is an excellent practice. But mandating a whole level of indirection just in case, just for the sake of it? Why?
Then I found out that not everything is an object, and I stopped wondering. My Python skills have improved since I understood that simple truth.
(
Log in to post comments)