Why does python not have a mechanism for data hiding?

Patrick Mullen saluk64007 at gmail.com
Tue Jun 3 02:45:29 CEST 2008


Can we plez not try and ruin my fave language with a useless concept?
Strict data hiding is only necessary because textbooks say it is.  Use
method attributes or some other hack if you really must (people won't know
it's there unless they look, and if they are looking, maybe they have a
reason?)

I heard a few emails back the argument that "you don't know how code might
be used", in favor of data hiding.  Um.  Excuse me?  You don't know how code
might be used to me is a good reason not to overly protect anything.  This
lets people use code in different ways than you might think.

Seriously, use java or some other such thing.  It's not like there aren't
plenty of other languages to choose from.  We aren't against data hiding
because we have python-colored glasses and are trying to stick up for our
favorite language after all.  For some of us, myself included, the lack of
data hiding is one of the plusses of the language.  I have done enough
development with big locked down systems to know how frustrating it is when
someone tells me how I am supposed to use them.  If data hiding were to
exist in python, someone would make a big system and use it excessively, and
it would eventually get very irritating.  Just like it is when working with
big c++ or java systems.

Please, just drop this topic.  It's ridiculous.  If you have customers who
use your code in bad ways, and then complain when you change something they
relied on you, I feel for you, but have you thought that maybe the way they
are trying to use it makes more sense than the way you are trying to force
them to?  Ok, most likely your way is better.  So hide the data a little
better, but there is still no reason to ENFORCE it.

Sorry for the rant, I don't usually rant, but this is a sore subject for me
and one that keeps me using python.  If the framework says I must do
object.move(-5), but the move function does collision detection, then I want
to be able to say object.x-=5 if I decide I don't need the collision
detection.  Maybe later the designer will decide that it is object.pos
instead of object.x, object.y, which will break my code.  My own damn
fault.  And if I don't feel like fixing it, I will subclass object, and make
x a property that returns and sets pos[0].  Or maybe the designer was nice
enough to do that for me himself.  I'm serious, if data hiding were added, I
would be looking around for another language.  I wouldn't stop using python
if no one used these features, but I would start looking for sure.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080602/7aff52ac/attachment.html>


More information about the Python-list mailing list