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

Antoon Pardon apardon at forel.vub.ac.be
Fri Sep 30 03:37:14 EDT 2005


Op 2005-09-29, Steve Holden schreef <steve at holdenweb.com>:

> Think about it: we have a language that has an eval() function and an 
> exec statement, and people are concerned that some service consumer 
> shouldn't be allowed to go poking around inside namespaces? What do we 
> have to do, put up signs saying "do not stab yourself with a knife"? If 
> people want control without discipline (which is effectively what 
> private and the like purport to do) then Python just may not be your 
> language ...

Well I have the following reasons not to like the current python way:

1) Beginning all your private variables with an underscore is like
starting all your integers with an 'i' or all your dictionary with
a 'd' etc.

2) The editor and font I use make it hard to see underscores. They
usually seem to belong more to the line below than to the actual
lines.

My idea as somekind of compromise between what happens in languages
like C++ and currently in python would be the following:

1) Allow keywords like private (or implemetation) to mark certain
variables, functions or classes as an implementation detail.
Personnally I would prefer the opposite such as a interface
to mark objects which are not private, but that would break too
much code.

2) Allow the client access to these private variables, through
a special construct. Maybe instead of "from ... import ..."
"from ... spy ...".

Just an idea.

-- 
Antoon Pardon



More information about the Python-list mailing list