classes (was Re: Same again please for OOP)

Moshe Zadka moshez at zadka.site.co.il
Mon Dec 25 13:25:20 EST 2000


On Mon, 25 Dec 2000, "Alex Martelli" <aleaxit at yahoo.com> wrote:

> Other languages may well-nigh force one to frame
> things up in terms of accessors/mutators, but that's an
> issue with *those* languages -- not one we should copy
> in Python, which lets us be more direct and simple.

You'd be right, if Python's __getattr__ would be better. There are a couple
of PEPs on the issue (Barry's, which AFAIK was rejected, and Paul's), just
to show many people in the Python's development team are dissatisfied. If
you've ever written a __getattr__ method, you probably know what a pain it
is. In contrast to the rest of Python, where I can code up 200-line application
with something on the order of 2 (easily found) bugs, __getattr__ always
seems to lead to twisted recursion bugs, and all kinds of headaches. 
*Particularily* if you also mix in __setattr__.

I've learned the hard way not to write __getattr__ methods. Currently, none
of my code contains them. True gurus, like Gordon McMillan, can use __getattr__
(e.g., in filecmp.py), to get lazy evaluation of attributes, but I tend to
fear those things.

The "computed attributes" interface needs to be improved befroe Python can
be said to be not one of *those* languages.

-- 
Moshe Zadka <sig at zadka.site.co.il>
This is a signature anti-virus. 
Please stop the spread of signature viruses!




More information about the Python-list mailing list