Getters and Setters
Tim Peters
tim_one at email.msn.com
Thu Jul 15 12:00:12 EDT 1999
[Neil Schemenauer]
> ...
> Bleech to CLOS or to Lisp or to automatic getters and setters?
Just to automagic attr manglers for class instances. Those grew out of
earlier gimmicks for modeling C-like structs, where they were more
appropriate.
> ...
> Your code is fast and elegant but it causes reference loops.
? Not under my Python <wink> -- stick a __del__ method in the test class
that prints something and you'll see that objects go away when you expect.
The function object assigned to self.set/get_XXX contains one ref to
self.__dict__ and another to the attr's string name, and that's it; it is
*not* a bound method object (which would also hold a reference to self),
just a function object. So there's no cycle unless you force one, like
instance.setWhatever(instance)
But then you would have had a cycle without this code too.
> only Python had real GC (and closures and macros and generators
> and coroutines and ...).
>
> Neil (running very quickly and hiding)
It's OK to want everything! It's just ill-advised to pine for it <wink>.
common-lisp-was-god's-experiment-to-see-whether-"everything"-
was-what-people-really-wanted-ly y'rs - tim
More information about the Python-list
mailing list