[Python-Dev] __mangled in stdlib considered poor form

Anthony Baxter anthony at interlink.com.au
Sat Aug 28 09:08:55 CEST 2004


I'd like to see all occurrances of __mangledName in the stdlib
removed and replaced with just _mangledName.

Rationale:

   The double-under "private" names are a hack. They don't really
protect variables, except against accidental stomping by subclasses.
Looking at the uses in the std lib, they're not being used for that -
they're being used for internal details. A single underscore is
sufficient for that.

   The mangled names cause problems when someone _needs_ to override
the implementation details in a subclass - I can recall a case with
ConfigParser in SpamBayes, where the end result was the subclass with
code like __ConfigParser_foo (a subsequent release of Python fixed
that instance of double-under madness). Yes, you shouldn't be fiddling
with internals of a class in a base class, and any time you do this,
you run the risk of being refactored into oblivion, but sometimes it's
necessary.

   Double-under mangled names are the worst of both worlds - they don't
actually protect the variables, but they force someone who needs to
poke into the class to use a mangled name.

   Given that part of the purpose of the stdlib is to act as a sort of
"best practice" example of Python code, I'd like to see all instances
of it in the std library removed.

   I'm not sure if it's feasible to attack this before 2.4b1, or if it
should wait until 2.5, but I _would_ like to see it happen.

   What sayeth the rest of python-dev?

Anthony
-- 
Anthony Baxter     <anthony at interlink.com.au>
It's never too late to have a happy childhood.


More information about the Python-Dev mailing list