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

Rocco Moretti roccomoretti at hotpop.com
Fri Sep 30 12:07:59 EDT 2005


Antoon Pardon wrote:

>>What if the class author removes a non-private variable or changes a 
>>method's documented parameters in the next version of the class, because 
>>he think it'll work better, or just because he can?
> 
> Changing an interface is different from changing the implementation.
 > A (documented) interface is like a contract. The implementation is
 > just one way to follow that contract.

Agreed. However, there is also a difference between an interface and 
"non-private variables."

E.g. you have a library, and playing with the code, you notice that by 
passing an empty string as a filename, you get the last file accessed. 
Cool. You write your program using this feature. Problem is, it's a 
quirk of the implementation, and in the next version, the library author 
fixes this "bug". Preventing access to private variables wouldn't help - 
the only thing you touched was the public parameter to a public function.

Of course, you could have avoided this by only using the documented 
interface, but if we go that route, you wouldn't have to worry about 
people accessing private variables, as they wouldn't be documented.

There is little in the way of technical problems that are solved by 
language level enforcement of private variables. The issues in question 
are mostly social ones, and if you're not reading and following the 
documented interface, stopping private variable access is not going to 
prevent most of your problems.

>> People who think that forbidding access to private variables/methods 
>> will save themselves from upgrade woes are deluding themselves.
 >
> It helps, just as locks wont save you from burglars if they really
> want to rob you, but the locks do help.

Right, but like doors that automatically lock when they close, items 
which are there to protect you can be a nusaince, especially when you've 
left your keys on the dining room table.



More information about the Python-list mailing list