what a cheap rule

Y

Yingjie Lan

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!

Regards,

Yingjie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top