"if {negative}" vs. "if {positive}" style

Gerald Britton gerald.britton at gmail.com
Wed Feb 10 16:27:36 EST 2010


On Wed, Feb 10, 2010 at 3:56 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> Tim Chase wrote:
>>
>> Any thoughts on how others make the choice?
>>
>> -tkc
>
> If one branch is only a few lines, it comes first.  As often as not, that
> tiny branch is checking for errors, and the "else" branch doesn't need to be
> indented.
>
> def func(arg1):
>    if arg1 is 'stupid':
>        raise ValueError("that's a stupid argument!")
>    do_something
>    do_something_else
>    etc, etc
>
>
> ~Ethan~
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Something similar in a for-loop:

for x in y:
   if not should_process(x): continue

  # process x

-- 
Gerald Britton



More information about the Python-list mailing list