Why does python not have a mechanism for data hiding?

Russ P. Russ.Paielli at gmail.com
Mon Jun 2 22:50:31 CEST 2008


On Jun 2, 6:41 am, Carl Banks <pavlovevide... at gmail.com> wrote:

> You are not realizing that only useful(**) thing about data hiding is
> that some code has access to the data, other code does not.  If you
> "hide" data equally from everyone it's just a useless spelling change.

I think you're missing the point.

As I see it, the primary value of data hiding is that it provides
useful information on which data and methods are intended for the
client and which are intended for internal use. It's like putting a
front panel on a TV set with the main controls intended for the
viewer.

People seem to be preoccupied with whether or not the back panel of
the TV is locked, but that is not the main issue. Sure, you probably
want to make the back panel removable, but you don't want the viewer
opening it up to change the channel, and you certainly don't want to
put all the internal adjustments for factory technicians together with
the controls for the end user.

As far as I am concerned, the current Python method of using
underscores to distinguish between internal and external methods and
data is an ugly hack that goes completely against the elegance of the
language in other areas. It is like a TV set with no back cover and
the volume and channel controls intermingled with the factory
controls. The underscores are just an afterthought like a red dot or
something used to tell the TV viewer  what to fiddle with.

Python is a very nice language overall, but as far as I am concerned
the underscore convention is a blemish. I just wish people wouldn't
get so infatuated with the language that they cannot see the obvious
staring them in the face.



More information about the Python-list mailing list