Feature suggestion -- return if true

Ethan Furman ethan at stoneleaf.us
Wed Apr 13 04:42:17 CEST 2011

Steven D'Aprano wrote:
> On Tue, 12 Apr 2011 16:48:31 -0700, Ethan Furman wrote:
>> Westley Martínez wrote:
>>> On Tue, 2011-04-12 at 16:06 -0700, Ethan Furman wrote:
>>>> --> def func():
>>>> -->     var1 = something()
>>>> -->     var2 = something_else('this') -->     return?
>>>> var1.hobgle(var2)
>>>> -->     var3 = last_resort(var1)
>>>> -->     return var3.wiglat(var2)
>>> The question mark makes the programmer look like he wasn't sure of what
>>> he was doing at the time.  "Hmm, should I return this object or not?"
>> Yeah, I'm definitely -1 on the ?, as well as -1 on the idea.  All other
>> major flow control uses indentation, and this does not.
> Neither return nor raise use indentation, and you don't get much more 
> major than those. Nor do list comps or generator expressions.

The indentation for return and raise is the next coded line.  List comps 
and gen exps are basically uber-functions, and regardless of how you 
categorize them when they finish it is easy to see where control goes to 
next because of indentation.  With this idea flow can leave the function 
with no indentation clue, making it easy to miss (assuming, of course, 
it's not some bright syntax highlighted color).


More information about the Python-list mailing list