Will python never intend to support private, protected and public?

Alex Martelli aleax at mail.comcast.net
Sat Oct 8 03:09:30 EDT 2005


Kay Schluehr <kay.schluehr at gmx.net> wrote:

> Honestly I like to use private/protect/public modifiers in C++ for the
> sake of code documentation. I like to know which attributes are
> dedicated to be known by other objects, which ones are for internal use
> only and which ones should be at least publicly accessible within a
> class hierarchy. This helps structuring code in the large and spotting
> attention. Code becomes easier accessible. But if we have Sunday or I

This advisory role is played in Python by naming conventions.  Start
attribute names with a single underscore to suggest "private but may be
easily overridden by subclasses" (roughly the equivalent of "protected";
Stroustrup is on record, in his book "The Design and Evolution of the
C++ Programming Language", as regretting the exact details whereby
"protected" became entrenched in C++, and wishing they could be
changed... I believe Python's single-underscore is somewhat better), two
underscores if you ever want to make names hard to override (I used to
like that, but as time goes by have come to like it less and less; right
now, unless I have to respect existing coding standards, I entirely
avoid the double-underscore usage, while single-underscores are OKish).


Alex



More information about the Python-list mailing list