[Python-ideas] for/else statements considered harmful
python at mrabarnett.plus.com
Thu Jun 7 18:32:45 CEST 2012
On 07/06/2012 16:52, Alice Bevan–McGregor wrote:
> On 2012-06-07 15:30:11 +0000, Mike Meyer said:
>> Calling it "wrap-up processing" seems likely to cause people to think
>> about it as meaning "finally". But if the else clause is not executed
>> if the except clause is (as done by try/except/else), then there's no
>> longer an easy way to describe it.
>> It seems like adding an except would change the conditions under which
>> the else clause is executed (unlike try/except/else), as otherwise
>> there's no easy way capture the current behavior, where else is
>> executed whenever there are no chunks left to process. But that kind
>> of things seems like a way to introduce bugs.
> Well, how about:
> for<var> in<iterable>:
> pass # process each<var>
> except: # no arguments!
> pass # nothing to process
> pass # fell through
> pass # regardless of break/fallthrough/empty
> Now for loops perfectly match try/except/else/finally!>:D (Like
> exception handling, finally would be called even with an inner return
> from any of the prior sections.)
Is the "finally" clause really necessary? Is it just the same as putting it
after the loop?
More information about the Python-ideas