[Python-ideas] Retrying EAFP without DRY

Nick Coghlan ncoghlan at gmail.com
Tue Jan 24 06:18:00 CET 2012


On Tue, Jan 24, 2012 at 2:44 PM, Mike Meyer <mwm at mired.org> wrote:
> That using an LBYL idiom, or simply repeating yourself, means you don't need a loop says to me that it isn't really a loop.  Which is why using loop to write it feels wrong.

A retry is just a specific kind of loop that executes 1 or 2 times (or
perhaps more if you're allowed to trigger the retry more than once).
You don't actually need loops in general, since you can use recursion
or repetition instead, so saying "look, i can rewrite it without the
loop, so it's not really a loop!" doesn't mean all that much in an
objective sense.

The argument that it might be worth having dedicated syntax for a loop
that runs 1 or 2 times is rather unconvincing when we don't even have
dedicated syntax for a loop that runs 1 or more times (see PEP 315).

We've survived this long with two variants of a loop that runs 0 or
more times and using break as appropriate to handle all the other
cases (e.g. while+break provides loop-and-a-half semantics and I've
written for loops with an unconditional break at the end to get "0 or
1" iteration). Making the case that we need another looping construct
is a fairly tall order (even PEP 315 doesn't suggest a completely new
construct - it only proposes a generalisation of the existing while
loops).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list