what a cheap rule

Yingjie Lan lanyjie at yahoo.com
Thu Nov 25 10:12:38 CET 2010

Sometimes the golden rule in Python of
"explicit is better than implicit" is
so cheap that it can be thrown away
for the trouble of typing an empty tuple.

Today when I am explaining that in Python 3,
there are two ways to raise exceptions:

raise Exception

raise Exception()

and that the first one is the same
as the second one, as Python will add the
missing pair of parenthesis. 

I felt their pain as they gasped.
Before that, I have already explained 
to them this piece of code:

try: raise SomeException()
except SomeException:
   print('Got an exception here')

by saying that the except-clause 
will match anything 
that belong to the SomeException class.

Without knowing this secrete
piece of information (that a
pair of parenthesis is automatically
provided), the following code
would be hard to understand:

try: raise SomeException
except SomeException:
   print('Got an exception here')

because the class object SomeException
is not an instance of itself, so 
a not-so-crooked coder will not
consider a match here.

So, the explicit is better than
implicit rule is thrown out of
the window so cheaply, 
that it literally worth less 
than an empty tuple!




More information about the Python-list mailing list