Why does python not have a mechanism for data hiding?

Patrick Mullen saluk64007 at gmail.com
Mon Jun 9 06:27:34 CEST 2008


"Well, "common" in Prolog, Smalltalk, Haskell, ML, and Erlang is hardly
common in general. I'll bet that Java and C/C++ are used more in North
Dakota than all those languages combined are used in the entire world."

I would say python has more in common with the mentioned family than with
the C or java families, although I guess it's more in between.

Perl, PHP and Ruby all have significant variable names also.  It is not that
uncommon.

2) Local data within functions is hidden. Should you have access to
that too? Are you insulted that you don't?

Local data within functions is not hidden.  Local data within functions
vanish when the function completes.  The ability for temporary
data is important, and the convention of having functions be
temporary keeps things sane.  Not quite the same as what this
discussion is about.  All of the attributes of an object also vanish
when the object does...

3) I have suggested that "indirect" or "back door" access could be
provided to private data and methods via some sort of name mangling
rule akin to the current rule for leading double underscores. This
would provide access in a pinch, but it would make sure the client is
aware that he or she or it is accessing private data (and it would do
so without leading underscores).

I honestly don't get the strong objection to leading underscores.
They are a low-tech way of saying "don't touch", which won't
muck about with very sticky implementation problems that
private attributes would have, potential performance problems
etc.  They work NOW.  Even if priv or some such is in the
running to be added to python, it's going to be years.

4) My understanding is that most Python software is released or
shipped as source code (or at least with the source code included).
That means that the client would need only to remove my suggested
"priv" keyword to gain access. Have you ever actually had to use
Python software for which you had no access to the source code?

So when someone releases an api doesn't match what I am doing 100%,
I should fork the project?  This doesn't seem to be a good solution
for anybody.  And it seems exceptionally dumb to do so just to
go through and remove some keywords.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080608/26056f94/attachment.html>


More information about the Python-list mailing list