Why does python not have a mechanism for data hiding?

George Sakkis george.sakkis at gmail.com
Mon May 26 18:21:07 EDT 2008


On May 26, 4:02 pm, "Russ P." <Russ.Paie... at gmail.com> wrote:

> Here's another suggestion. Why not use "priv" as shorthand for
> "private"? Then,
>
> priv height = 24
>
> at file scope would make "height" invisible outside the module by
> default. And the same line in a class definition would give "height"
> the equivalent of "protected" status in C++.

On a slightly different question: can a data hiding mechanism be
implemented as an add-on by a third party library without a change in
the core language, just like zope.interface does for interfaces ? If
not, why not ?

> I think "height" looks cleaner than "_height". And isn't clean code a
> fundamental aspect of Python?

Note that even in languages that do implement data hiding, people
often use a naming convention to denote hidden members, e.g. an "m_"
prefix (though I find this uglier than plain underscores).

George



More information about the Python-list mailing list