[Python-Dev] Re: switch statement

Michael Walter michael.walter at gmail.com
Thu Apr 28 14:46:22 CEST 2005


On 4/28/05, Stephen J. Turnbull <stephen at xemacs.org> wrote:
> >>>>> "Guido" == Guido van Rossum <gvanrossum at gmail.com> writes:
> 
>     Guido> You mean like this?
> 
>     if x > 0:
>         ...normal case...
>     elif y > 0:
>         ....abnormal case...
>     else:
>         ...edge case...
> 
> The salient example!  If it's no accident that those conditions are
> mutually exclusive and exhaustive, doesn't that code require at least
> a comment saying so, and maybe even an assertion to that effect?

I usually do:

if ...:
  return ...
if ...:
  return ...
assert ...
return ...

Michael


More information about the Python-Dev mailing list