Coding style and else statements

Steve Holden steve at holdenweb.com
Wed Aug 30 02:52:02 EDT 2006


Carl Banks wrote:
[...]
> However, I have rare cases where I do choose to use the else (ususally
> in the midst of a complicated piece of logic, where it's be more
> distracting than concise).  In that case, I'd do something like this:
> 
> def foo(thing):
>     if thing:
>         return thing+1
>     else:
>         return -1
>     assert False

I think that's about the most extreme defensive programming I've seen in 
a while! I can imaging it's saved your ass a couple of times when you've 
edited the code a while after writing it.

Of course, optimising will remove the assertions ...

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list