ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: Underscore data hiding (was python development practices?)
by Martijn Faassen other posts by this author
Oct 31 2001 11:54PM messages near this date
Re: Underscore data hiding (was python development practices?) | Re: Underscore data hiding (was python development practices?)
Russell E. Owen <owen@[...].emu>  wrote:
>  This brings up an issue about using underscore to hide data...

>  My understanding is that a double underscore is required for Python to 
>  automagically mangle the name.

That is correct.

>  On the other hand, two postings now 
>  suggest that a single underscore is sufficient.

>  If double underscore is required, then it seems to me this is a very 
>  common misconception that a single is sufficient. It might be worth 
>  changing.

The double underscore is required for name mangling, but I don't really
like the name mangling; it gets in the way. I just want to give the 
programmer a hint that some attribute is private, and I use a single
underscore for this, and many Python programmers with me.

Why does name mangling get in my way? Generally I like to be able to
reach the private variables in subclasses (I suppose this makes them
protected in C++ terms, though my C++ is rusty). I also like being
able to fake things easily in case I need it, for debugging and
testing purposes. In the end I only want to indicate something is private
without all the hassle of name mangling.

Data hiding isn't there to prevent evil programmers from doing evil
things anyway; it's there to communicate intent and to prevent people
from tripping over problems. At least in C++ they can do such evil things as 
#define private public before including a header file. Besides Python
has a tradition of flexibility and open source.

Finally, in Zope an underscore does have a meaning (it makes it private
in the Zope security sense).

>  If double is not required, I'd love to know about it. Single looks a lot 
>  neater, and I'm not fond of double punctuation symbols that are hard to 
>  read anyway.

It's not required to make something be private in the intent sense. It's
only needed to make something private in the name mangling sense. :)

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?
-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Peter Wang
Peter Hansen
Toby Dickenson
Tim Peters
Steve Holden
Steve Holden
Cliff Wells
Tim Peters
Martijn Faassen

Cliff Wells
Cliff Wells
Martijn Faassen
Martijn Faassen
Paul Rubin
Russell E. Owen
Barry A. Warsaw
Martijn Faassen
Peter Wang
Skip Montanaro
John Roth
David Bolen
Peter Wang
Peter Wang
Skip Montanaro
Chris Tavares
Darren Collins
David Bolen
Paul Rubin
Paul Rubin
Peter Wang
F Basegmez
Richard Jones

Richard Jones

Neal Norwitz
Graham Ashton
Peter Wang
Russell E. Owen
Skip Montanaro
Cliff Wells
Hung Jung Lu
Wade Leftwich
Peter Wang
Peter Wang


Peter Wang

Chris Gonnerman
Paul Rubin
Andrew Dalke
Paul Rubin
Luigi Ballabio
Paul Rubin
Tim Peters
John Roth
Paul Rubin
Richard Jones

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved