Coding style and else statements

Ben Finney bignose+hates-spam at benfinney.id.au
Wed Aug 30 03:02:44 EDT 2006


"Carl Banks" <pavlovevidence at gmail.com> writes:

> 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

To my eyes, that's less readable than, and has no benefit over, the
following:

    def foo(thing):
        if thing:
            result = thing+1
        else:
            result = -1
        return result

-- 
 \     "Ours is a world where people don't know what they want and are |
  `\    willing to go through hell to get it."  -- Donald Robert Perry |
_o__)                                                          Marquis |
Ben Finney




More information about the Python-list mailing list