[Python-ideas] Retrying EAFP without DRY
mwm at mired.org
Tue Jan 24 19:09:34 CET 2012
On Mon, 23 Jan 2012 21:19:08 -1000
"Carl M. Johnson" <cmjohnson.mailinglist at gmail.com> wrote:
> On Jan 23, 2012, at 9:00 PM, Nick Coghlan wrote:
> > On Tue, Jan 24, 2012 at 3:47 PM, Mike Meyer <mwm at mired.org> wrote:
> >> The argument isn't that we need a new syntax for a small set of
> >> loops, it's that the only ways to implement retrying after an
> >> exception leave a code smell.
> > Uh, saying "retrying is fundamentally a looping operation" is not a
> > code smell.
> I do think there's something code smelly about a retry--if it didn't
> work the first time, why should it work the second time after you
> give it a whack? Either whacking is good and you should do it in
That's the LBYL way of expressing the code. You know, the one that
manages to express the "loop" without either repeating any code or
using an actual loop. Except applying the fix without checking to see
if it's needed is most likely a bug.
You might want to argue that LBYL isn't a code smell. I've fixed
enough bugs caused by it to disagree, but at this point it's a style
More information about the Python-ideas