Which way to say 'private'?

John J. Lee jjl at pobox.com
Fri Aug 22 17:15:55 CEST 2003

Jacek Generowicz <jacek.generowicz at cern.ch> writes:

> "Batista, Facundo" <FBatista at uniFON.com.ar> writes:
> > As a I read don't remember where, :p, to put 1 underscore is the
> > same to hang a "Do not disturb" sign in the door, to put 2
> > underscores is the same to lock the door.
> ... and to put the key under the mat in front of the door. (On the
> outside :-)
> Any fool who cares to look, can figure out and circumvent the name
> mangling scheme. It offers no protection against intruders. It does
> offer protection against name clashes, and that is its purpose.

And, just to reiterate, both _ and __ offer protection against
accidental intruders (not the same as accidental name-clashes).  And
__ does offer some protection against thoughtless abuse of
implementation where there's an interface to do the job.

So, to sum up, contrary to popular belief, all of this is roughly the
same in any language -- one can always get around the restrictions
(though maybe not feasibly in some cases with Java?) -- they're there
only to prevent accidents and casual abuse.  Hence the argument often
put forward here that making access restrictions *too* awkward to work
around is actually a real mistake -- interface designers *have* been
known to make mistakes <wink>.


More information about the Python-list mailing list