[XML-SIG] Ugh! Why are DOM access methods spelled with a leading '_'?

Michael McLay mclay@nist.gov
Mon, 26 Jun 2000 13:38:44 -0400 (EDT)

Uche Ogbuji writes:
 > I should note that I quite hope that leading-underscore-means-private
 > is indeed not normative, and never will be so.  The leading underscore
 > is the most readable way to escape symbol names that would clash with
 > an applicable naming convention.  

The use of a single "_" at the front of a name in Python has always
(at least since about Python 1.2) been used to filter out names that
should not be used outside a module.  It is more than an idiom.  The
concept is enforced in statements of the form "from foo import *".  It
isn't absolutely enforced.  You can still say  "from foo import _thing".

Arguing that other languages use "_" to eliminate name conflicts is a
red-herring when talking about Python.  Python namespaces make this
unnecessary.  It is annoying to some Python users to see an idiom from
another language carried over to Python.  In this case the carryover
directly conflicts with a Python language feature.

 >  It's far from a conclusive argument
 > (though Jim Fulton tried to make a similar argument to excoriate the
 > Python/CORBA binding), but most languages, such as C++ allow exactly
 > this approach as put to good use by the C++/CORBA binding.

 > The leading-underscore-is-private idea has the annoying effect that if
 > I want to call a variable "class", I must instead use the silly
 > "klass", rather than "_class", which is far more readable and
 > self-explanatory.  And if I want to call variables "def", "type" and
 > "else", what then?  "deph", "tipe" and "els"?  (I suppose one could
 > use trailing underscore).

Why not use append a "_" to the name to distinguish it from a keyword.
The name "class_" would be as readable and it wouldn't conflict
with the longstanding Python rule for leading "_" characters.

 > Most likely, Guido is already in his time machine writing "Thou shalt
 > not use leading underscore except for private variables" on a stone
 > tablet somewhere in the past to end the whole argument.  But people
 > have been saying nasty things about the Python/CORBA binding which
 > wouldn't be as nasty as the things I'd say about such a restriction in
 > Python.

The special meaning of _* is defined here: 

The rule is also discussed in section 6.1 of the Tutorial.