PEP 318: Can't we all just get along?

Anthony Baxter anthonybaxter at gmail.com
Fri Aug 20 12:10:31 CEST 2004


On Fri, 20 Aug 2004 05:57:42 -0400, Paul Morrow <pm_mon at yahoo.com> wrote:
> I know you weren't Anthony (that was a joke).  I understand that you
> don't like this idea, but that doesn't make it a _bad_ one. Numerous
> people have *not* effectively pointed out the problems with it (and
> neither have you, sir).

Err, what? Have you bothered to read the replies I sent to you? This 
is _bad_ magic behaviour. Python does not care about argument lists
now, and adding this is icky. Your behaviour when _adding_ methods 
to classes is extremely undefined, particularly in the presence of 
descriptors. Explaining this to new users would be complex. It's a 
messy interference in the way Python's OO builds classes and objects,
which is currently very clear and easy to follow[1]. It's not explicit, but
implicit. How many ways do I have to spell this out? 

[1] with the double-underscore mangling put to one side, or preferably,
off a bridge.

The only argument _for_ this that you've offered is that it's just like the
double-underscores. This is a losing argument (with me, anyway) as
I regard the double-underscore mangling as awful - that sort of "data
hiding" just ends up being a pain in the arse when you want to poke 
with a class's internals. Python regards everyone as an adult in that 
respect, unlike the "protecting you from yourself" C++ nightmare. In
addition, the double-underscore is just random magic that occurs when
a class is created, not subsequently:

>>> class A:
...   __foo = 1
... 
>>> dir(A)
['_A__foo', '__doc__', '__module__']
>>> A.__bar = 2
>>> dir(A)
['_A__foo', '__bar', '__doc__', '__module__']

for the same reasons, your idea would lead to inconsistencies.

Anthony



More information about the Python-list mailing list