Callable assertion?

Peter Hansen peter at engcorp.com
Sun Oct 5 22:23:28 EDT 2003


Terry Reedy wrote:
> 
> Alex Martelli has written several pages on 'look before you leap' (his
> phrase) ...

That just put an image in my mind, of someone carefully inspecting
a chasm over which he intends to jump, measuring distance, making
sure that it's within his abilities.  

He then backs up ten carefully measured paces, digs in his feet, 
and surges forward, sprinting at top speed.

He flies towards the gap, his paces perfectly timed.

At the last moment, just as he launches himself into the air, the
ground under his foot crumbles away and he tumbles helplessly into
the void.

It might sound like a good idea, and even perhaps be a good idea,
to check things out ahead of time, but it's essential to understand
that, no matter what, you could overlook something or conditions
could change at the last instant just as you "do it for real".

Whether you use an assertion in __init__, or any other kind of
"look before you leap", just make sure to remember that you might
have overlooked some obscure way in which things could fail anyway.

Always handle exceptions.  There's no robust alternative.

-Peter




More information about the Python-list mailing list