[Python-ideas] Name mangling removal ?
Guido van Rossum
guido at python.org
Sun Feb 1 17:30:31 CET 2009
On Sun, Feb 1, 2009 at 4:40 AM, Tarek Ziadé <ziade.tarek at gmail.com> wrote:
> I have found several posts of people (including Python commiters)
> asking for the removal of name mangling in Python,
> (the latest in 2006 in python-3000). I have searched in the various
> mailing lists and I can't find a clear status on this.
This is the first time I've heard of this request.
> If someone knows please let me know.
AFAIK it's never been brought up on python-dev while we were discussing Py3k.
> Otherwise : I would like to propose this feature to be removed because
> it brakes Python philosophy imho.
I'm against removing it. While the "privacy" it offers is marginal, it
also offers protection against accidental clashes between attribute
names. E.g. consider person A who writes a library containing a class
A, and person B who writes an application with a class B that
subclasses A. Let's say B needs to add new instance variables, and
wants to be "future-proof" against newer versions of A that might add
instance variables too. Using name-mangled variables gives B a
"namespace" of his own (_B__*), so he doesn't have to worry about
clashes between attribute names he chooses now and attribute names
that A might choose in the future. Without name-mangling, B would have
to worry that A could add private variables with clashing names as
well -- in fact, the presence of any private variables in A would have
to be documented in order to ensure that subclasses wouldn't
accidentally clash with them, defeating the whole purpose of private.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-ideas