[Python-Dev] Deprecate __ private (was Re: PEP 8 updates/clarifications)

Jim Fulton jim at zope.com
Mon Dec 12 12:33:38 CET 2005


Tim Peters wrote:
> [Neal Norwitz]
> 

...

> That was the only point to `__` name-mangling.  People who think it's
> trying to, e.g., emulate C++'s `private` gimmick are enjoying a
> semi-private fantasy ;-)  It works fine for its intended use.

In theory, I agree.

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.

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