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

Mike Meyer mwm at mired.org
Wed Sep 28 11:28:32 EDT 2005


Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:

> Chris Gonnerman <chris.gonnerman at newcenturycomputers.net> writes:
>> -- Make it easy to do right.
>> 
>> What you are promoting is the first philosophy: Tie the programmer's
>> hands so he can't do wrong.  Python for the most part follows the
>> second philosophy, making writing good code so easy that the coder
>> is rarely tempted to commit any evil.
>
> Unless you can show that all Python code is bug-free, you've got to
> consider that there might be something to this private and protected
> stuff.  See for example this message:
>
>   http://groups.google.com/group/sci.crypt/msg/59516419dc874e63?dmode=source
>
> Name mangling is a poor substitute for private variables.  If you want
> to be able to share private variables with other classes under certain
> circumstances, it's better to use something like C++'s "friend"
> declaration, where you can export the variables to a specific other class.

Note that the quoted article only applies to *writing* attributes. It
doesn't say anything about needing accessors to *read* a
variable. This encourages me that the convention I use - adopted from
Eiffel, where the compiler enforces it - of freeling reading
attributes, but providing methods to write them - is a right way todo
things.

        <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list