![]() |
Available news archives:
comp.lang.tcl
-
comp.lang.python
-
comp.security.firewalls
-
sci.crypt -
comp.lang.php -
comp.lang.javascript
|
|
comp.lang.python archiveRe: Should I use "if" or "try" (as a matter of speed)?
From: Roy Smith <roy@panix.com>
Date: Sat Jul 09 2005 - 21:06:07 CEST
Steve Juranich <sjuranic@gmail.com> wrote:
Well, you've now got a failure. I used to write Fortran on punch cards, so
> I think that the argument goes something like, "When you set up a 'try'
That sounds like a very C++ kind of attitude, where efficiency is prized
> What do I mean by "cheaper"? I'm basically talking about the number
Don't worry about crap like that until the whole application is done and
Exceptions are better than returning an error code for several reasons:
1) They cannot be silently ignored by accident. If you don't catch an
2) It separates the normal flow of control from the error processing. In
3) In some cases, they can lead to faster code. A classic example is
count = {}
compared to
count = {}
if most keys are going to already be in the dictionary, handling the
|