Why does python not have a mechanism for data hiding?

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Tue Jun 3 17:16:44 CEST 2008

Russ P. a écrit :
> 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. 

As far as I'm concerned, it's JustFine(tm). I don't have to ask myself 
if an attribute is part of the API or not, I know it immediatly.

> 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.

Your opinion. But beware of leaky TV-Set-metaphor abstractions

> 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.

I definitively don't have problem with this naming convention, which I'd 
find useful ever with a language having enforced access restrictions. If 
that's the only - or worse - wart you find in Python, then it must 
surely be a pretty good language !-)

More information about the Python-list mailing list