get/set

Kragen Sitaker kragen at pobox.com
Tue May 14 20:28:34 EDT 2002


weeks at vitus.scs.agilent.com (Greg Weeks) writes:
> Putting aside __getattr__, __setattr__, __getattribute__, properties, and
> __slots__, then whether or not you define get/set methods is a matter of
> style, just as in Java and C++.  As in Java and C++, I consider it to be
> good style.

The reason you define trivial get/set methods in Java and C++, instead
of just making the instance data public, is that you might want to
change your implementation later on without having to change all the
clients that call it.

The point of properties is that they let you change your mind about
such things later on, so your clients that previously set and read
instance data directly are now transparently calling getter and setter
methods.  If you're programming in a dialect of Python that supports
them --- that means, you don't have to be backward compatible with
2.1, a rare situation today but probably a common one around 2005 ---
then you don't have to waste your time and your readers' time with
stupid get and set methods that do nothing useful.




More information about the Python-list mailing list