[Python-ideas] Name mangling removal ?

Guido van Rossum guido at python.org
Sun Feb 1 23:32:01 CET 2009


On Sun, Feb 1, 2009 at 1:40 PM, Tarek Ziadé <ziade.tarek at gmail.com> wrote:
> On Sun, Feb 1, 2009 at 5:30 PM, Guido van Rossum <guido at python.org> wrote:
>> This is the first time I've heard of this request.
>
> The most recent one is here I think :
> http://mail.python.org/pipermail/python-3000/2006-September/003857.html

Thanks for refreshing my memory. But the explanation below holds -- it
should stay.

>> 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.
>
> Right, thanks for the explanation,
>
> I found back a thread where it has been discussed already so I'll study it
>
> http://mail.python.org/pipermail/python-dev/2005-December/058555.html
>
>
> Regards
> Tarek
> --
> Tarek Ziadé | Association AfPy | www.afpy.org
> Blog FR | http://programmation-python.org
> Blog EN | http://tarekziade.wordpress.com/
>



-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-ideas mailing list