[Python-ideas] Retrying EAFP without DRY
ncoghlan at gmail.com
Tue Jan 24 04:56:38 CET 2012
On Tue, Jan 24, 2012 at 1:18 PM, Stephen J. Turnbull <stephen at xemacs.org> wrote:
> I don't think syntax can express that cleanly, but I can't help
> thinking it's of good thing if somebody like Mike tries to find a way.
> He might succeed!
Special casing "looping with at most two iterations" and "looping
where the body is a single try statement" both seem like very poor
OK, so some people apparently take issue with having to map "retry" to
"loop", but how does that even come close to justifying making
*everyone* learn a third looping construct?
We can't even get consensus that PEP 315's generalised while loops
(which allow you to write loop-and-a-half constructs without using
break) would be a net win for the language over the existing idiom.
I'll note that under PEP 315, the problem discussed in this thread
could be handled as:
do ... while retry: # '...' stands in for the suite below
retry = False
# attempt consistent operation
# set up for next attempt based on result of current attempt
# even the list of expected exceptions can be made dynamic!
retry = True
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas