[Python-ideas] Retrying EAFP without DRY
Carl M. Johnson
cmjohnson.mailinglist at gmail.com
Tue Jan 24 08:19:08 CET 2012
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 advance or it's bad and you should do something more sophisticated--but I don't see how creating language level support for retrying would remove the smell. Accessing deeply.nested.methods.and_.properties is a code smell too, even though it has language level support from Python. (You could imagine it being otherwise, if Python insisted that each attribute access get its own line, but that wouldn't remove the smell either.)
The whole point of a "smell" is that it's not directly bad, but it's a sign that maybe you were thinking of something wrong at a different level, so it's time to re-architect a little.
More information about the Python-ideas