RFC: Assignment as expression (pre-PEP)
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Thu Apr 5 19:53:22 EDT 2007
Duncan Booth a écrit :
> TimeHorse at gmail.com wrote:
>
>
>>Performing a list of mutually exclusive checks that require data
>>processing can cause excessive tabification. For example, consider
>>the following python snipet...
>>
>>temp = my_re1.match(exp)
>>if temp:
>> # do something with temp
>>else:
>> temp = my_re2.match(exp)
>> if temp:
>> # do something with temp
>> else:
>> temp = my_re3.match(exp)
>> if temp:
>> # do something with temp
>> else:
>> temp = my_re4.match(exp)
>>
>
>
> Can you come up with a real example where this happens and which cannot be
> easily rewritten to provide better, clearer code without the indentation?
>
> I'll admit to having occasionally had code not entirely dissimilar to this
> when first written, but I don't believe it has ever survived more than a
> few minutes before being refactored into a cleaner form. I would claim that
> it is a good thing that Python makes it obvious that code like this should
> be refactored.
+2 QOTW
More information about the Python-list
mailing list