Getters and Setters

Neil Schemenauer nascheme at ucalgary.ca
Thu Jul 15 05:29:00 EDT 1999


Tim Peters <tim_one at email.msn.com> wrote:
>[Neil Schemenauer]
>> Recently I found myself wishing that Python had automatic getters
>> and setters like CLOS.
>
>Bleech.

Bleech to CLOS or to Lisp or to automatic getters and setters?

>Python goes one better: you can write an explicit method if
>needed, but it doesn't encourage bad practice by automatically
>supplying methods that expose every data attribute, crying "use
>me! abuse me!" <wink>.

Point taken.  However, currently I am writing some simulation
software that has objects with lots of publicly accessible,
simple, attributes (ie. reals).  Only a few need special
treatment.  I'm getting bored writing all these little functions.

>And some later corrected code boosted the factor to 10.

Actually the code had to be corrected a third time.  There is
nothing like showing off your incompetence in front of hundreds
(thousands?) of people. :(

>I'll attach code that gets to the same end, but where the
>automatic methods actually run faster than explicit ones. I
>won't say why, though <wink -- but you'll figure it out>.

Your code is fast and elegant but it causes reference loops.  If
only Python had real GC (and closures and macros and generators
and coroutines and ...).


    Neil (running very quickly and hiding)




More information about the Python-list mailing list