[Python-Dev] Deprecate __ private (was Re: PEP 8 updates/clarifications)
Jim Fulton
jim at zope.com
Tue Dec 13 12:45:42 CET 2005
Guido van Rossum wrote:
> On 12/12/05, Jim Fulton <jim at zope.com> wrote:
>
>>In practice, I don't agree that it works fine. Inevitably, someone
>>finds a need to access a "private" variable in a subclass. Or
>>even in the original class, you find some need to use something like
>>__getattr__ where the implicit name mangling doesn't come into play
>>and you have to emulate the name mangling. Or perhaps someone wants
>>to examine the value of one of these variables in the debugger.
>>In my experience, almost every time someone uses the __private
>>trick, they or someone else comes to regret it.
>>
>>OTOH, explicit name mangling provides the benefits of implicit
>>name mangling without it's drawbacks.
>
>
> I half agree. I've seen many classes overuse __private.
As I point out above, it's not just a matter of overuse. It
is only recognized by the compiler, so it doesn't work with getattr.
And of couuse, there's the debugger issue. I've often found
cases where, even when I was using it correctly, I had to do manual
name mangling myself. Anytime one has to perform weird tricks
in Python to work around magic should be a warning sign.
> But that's a
> separate issue from not having the feature at all; you might as well
> argue against private in Java or C++.
I'm not arguing against the feature but against it's implementation.
My intuition is that the explicit name magling approach is more in
keeping with Python's way of doing things.
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the Python-Dev
mailing list