Underscore data hiding (was python development practices?)

Toby Dickenson tdickenson at devmail.geminidataloggers.co.uk
Mon Nov 5 07:35:58 EST 2001


barry at zope.com (Barry A. Warsaw) wrote:

>FWIW, the double-leading-underscore-no-trailing-double-underscore name
>mangling rule wasn't added specifically for data hiding.  It was so
>that a class that was designed to be subclassed could have a namespace
>that subclasses couldn't accidently trample on:

Interestingly, I often find that that the chosen mangling scheme
doesnt achieve that design goal. The scheme mangles the class name
into the underscore-stripped attribute name, which offers zero
protection if your base classes and subclasses have the same name.

Does this happen often? A common structure (for me, anyway) is to have
modules BaseWidget, FooWidget, and BarWidget, all of which define a
class Widget.



Toby Dickenson
tdickenson at geminidataloggers.com



More information about the Python-list mailing list