First of all, the reason that private members can be hacked in C++ because of 
pointers. I don't know Java, so I don't know how it's possible there. But 
Python doesn't have pointers and getattr, settatr can be adjusted to work with 
private members. The only way the hack is possible if someone wrote a Extension 
module in which they would get a PyObject* as a parameter and from there they 
would manually get the attribute variable using pointer and then return the 
value. Therefore if private is implemented in Python it would be more secure 
than private in other OOPs.

The benefit of private is actually debugging. If somehow, someone finds that 
the private member has changed they would immediately know that it was a memory 
leak or the value was changed through a set method defined in the class (This 
is one of most important pillar of access modifiers in OOP). Python's private 
convention most of the time helps but since it doesn't enforce it someone just 
might introduce a bug in an application by modifying a private member. I just 
gave an example of security it was not the main point.

The main aim of private is to avoid modifying not accessing. I know @property 
can be used to turn a member variable into a non-modifiable member variable but 
that also means you can't change it inside the class also.

When applying private on functions, I think that's when it becomes private. 
You're hiding interfaces when you don't need to. In fact hiding interfaces is 
worse than hacking. Functions can't be hacked.

Conclusion
------------

Therefore I actually kind of change my suggestion to introduce a new keyword 
that avoids modifying member variables from outside the class not the inside. 
This would preserve @property behavior plus introducing a new kind of behavior. 
 Also this member variables would be inherited.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/426EPANCVEGZV2AZL7MWNG67BTZMORNG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to