Raising objects

Steven Taschuk staschuk at telusplanet.net
Thu May 1 21:52:25 EDT 2003


Quoth Michael Chermside:
  [...]
> Not that performance is the the be-all and end-all of design, nor
> is exception handling the most important place to optimize, but
> it's kinda neat that it saves this unnecessary object creation
> JUST SO LONG AS it goes ahead and creates the object if you ever
> do anything which would access that object.

That's an interesting idea.  But I'm not sure the performance
advantage (if there is one) is worth the weirdness.

For example, what if my snazzy subclass of Exception has an
__init__ with side-effects?  Then either (a) I raise the class and
the side-effects happen at some future time, maybe, or (b) I have
explicitly ask for an instance.

This makes
    raise MyException
and
    raise MyException()
subtly different; worse, the distinction is almost always
irrelevant, so coders will forget about it until one day they
write an exception class which needs to be initialized right away
(or needs not to be), whereupon they need to pay attention to a
distinction which they've never had to pay attention to before.

I feel that the possibility (likelihood, imho) of this kind of
gotcha outweighs the advantages of lazy exception creation, which
strike me as quite minor.

-- 
Steven Taschuk                staschuk at telusplanet.net
"I tried to be pleasant and accommodating, but my head
 began to hurt from his banality."   -- _Seven_ (1996)





More information about the Python-list mailing list