[Python-ideas] Loop labels

Nick Coghlan ncoghlan at gmail.com
Fri Mar 9 12:27:46 CET 2012


On Fri, Mar 9, 2012 at 9:08 PM, Matt Joiner <anacrolix at gmail.com> wrote:
> It's something that comes up enough to be of use. I'd compare it to
> the with statement, which isn't always useful, but handles the
> majority of such cases. A goto is the full fledged try/finally
> equivalent.

You are setting your bar for new syntax proposals *way* too low. In a
language with an iterator protocol, many nested loops are better
written as generators with an embedded return. Labelled loops then
become an attractive nuisance that distracts people from other ways to
structure their algorithm such that it is easier to maintain.

So no, you can't just wave your hands in the air and say "It's
something that comes up enough to be of use" and get away with it.

PEP 380 only got away with being a bit sketchy on concrete use cases
because generators that were used with send() and throw() so clearly
couldn't be refactored properly in a post-PEP 342 world. PEP 343 met
the much higher bar of making it easy to deal with a wide range of
*extraordinarily* common tasks like closing files, using thread
synchronisation primitives, standardising exception handling, etc,
etc. Loop labels have never even come *close* to attaining that
standard.

Regards,
Nick.

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



More information about the Python-ideas mailing list