Exception handling wart in Python (or, pehaps, underscores)

Tony J Ibbs (Tibs) tony at lsl.co.uk
Fri Nov 2 16:47:13 CET 2001


Leo Lipelis demonstrated in earlier messages his dislike of "magic
underscores" (gosh, I remember *discussion* about whether using "__" at
the beginning of a name to indicate mangling was a good or bad thing -
how time flies) and then wrote:
> Point is, Python can be made better by getting rid of the
> "self.__" in front of every object attribute.
...
> But the double underscore is a bad hack.  It's not elegant
> or brief or intuitive.  When you actually *use it a lot* it
> really grows old fast.  It seems like a feature invented by
> someone who never actually uses it much.

Aha, I go, then maybe that means (ta da!) that one *shouldn't* use it a
lot...

It's *very* tempting, when going from one language to another, to try to
hang on to the tools and habits that one has evolved in the earlier
language. Unfortunately, it's also quite hard to tell (well, at least
for me) which tools and habits  are going to be *useful* in the new
language, certainly until one has enough experience in it. And it seems
to me that comparing methodologies in a statically typed language where
exceptions are, well, exceptional with Python, where objects are typed
but names aren't, and where exceptions are fairly common [1]_, may be
taken to be, well, not a labour of love.

But maybe I've just programmed in enough different languages to assume
that they are, in fact, different.

I must admit that, since I love Python as it is, I always have some
difficulty with people who want to change its appearance radically.
Luckily for me, Python comes with its very own BDFL, and he *is* a good
language designer, and he knows when to say no (or, perhaps more
importantly, when to just ignore things).

.. [1] I wonder if Edward Welbourne ever followed up on his
   Python-variant in which exceptions were, if I remember
   correctly (and I never fully understood it) the main
   underlying mechanism for the interpreter. Strange stuff.
Tibs

--
Tony J Ibbs (Tibs)      http://www.tibsnjoan.co.uk/
"I'm a little monster, short and stout
 Here's my horns and here's my snout
 When you come a calling, hear me shout
 I will ROAR and chase you out"
My views! Mine! Mine! (Unless Laser-Scan ask nicely to borrow them.)





More information about the Python-list mailing list