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

Mike Meyer mwm at mired.org
Thu Sep 29 00:35:50 CEST 2005


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

> Gregor Horvath <g.horvath at gmx.at> writes:
>> > 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.
>> 
>> That assumes that you always know for sure that the given variable
>> will always be used as a private/friend variable in the lifecycle of
>> the software.
>
> Obviously if you find you need to use it in another place later, you
> update the declaration.  The idea is for you (or an automatic tool) to
> be able to find all the uses of some instance variable.  In Python
> (because of things like setattr), that can't be done.

One of the advantages of avoiding boilerplate is that you avoid the
need to maintain it.

It's not clear that tracking all uses of a variable in Python can't be
done. It's clear that it's *difficult* - you have to track the objects
bound to both arguments for ever setattr call - but that's not the
same thing as impossible. My gut says "halting problem", but I haven't
proved it. Most other languages aren't that different - unless you
place serious restrictions on them. For instance, most languages will
let me pass a reference to an instance variable to a method of another
object. If that method then stores the reference in a global (or
class, or instance) variable, you suddenly have to track the value of
that new variable to figure out if the variable of interest is being
used whenever the new one is used. Which is pretty much the same place
you get with setattr.

      <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