[Python-Dev] Chaining try statements: eltry?

Guido van Rossum gvanrossum at gmail.com
Thu Jul 7 15:39:30 CEST 2005


On 7/7/05, Thomas Lotze <thomas at thomas-lotze.de> wrote:
> Sure, that's true for the example given. Getting other stuff into a form
> which allows for looping may require additional code.

Well, hypothetical illustrations don't carry much value when arguing
for something as substantial as new syntax requiring a new keyword.
You have to present an actual use case with an indication (even if
only anecdotal) of how common the use case is, and an explanation why
the existing ways of handling that use case are inadequate.

Your illustration doesn't count as a use case because it is easily
handled already.

> Thinking about it some more, I find that a symmetry between statements
> which have an 'else' part would be appealing from an aesthetic point of
> view, which includes introduction of 'elfor' and 'elwhile' - or allowing
> for syntax like 'else if ...:' and 'else try:'. (It seems some people
> favour that anyway. OTOH, I undestand that introducing two-token
> constructs doesn't necessarily simplify parsing.) But I haven't
> encountered any use cases for that, so it's probably just idle musing.

The parsing would be easy enough (and in fact I sometimes think it was
a mistake to introduce elif just to save typing "else if".

The problem with the elwhile/elfor/eltry idea (apart from the
explosion of new keywords) is that you're just as likely to need e.g.
a "try" in the else clause of a while-loop as another while, so you'd
end up having all combinations in the syntax. Since, as you say, the
use cases are rare, the syntactic complexity isn't worth it.

I even wonder if else-clauses on for/while were a good idea. (The one
on try is definitely a good idea since the use case is quite frequent
and only clumsily handled otherwise; the use cases for else on
for/while are less convincing IMO.)

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list