[Python-Dev] PEP-xxx: Unification of for statement and list-comp syntax
Heiko Wundram
me+python-dev at modelnine.org
Sun May 21 23:17:46 CEST 2006
Am Sonntag 21 Mai 2006 22:11 schrieb Talin:
> As a general guideline, I've noticed that proposals which are purely
> syntactic sugar are unlikely to be accepted unless there is some
> additional benefit other than just compression of source code.
I know about this, but generally, I find there's more to this "syntactic
sugar" than just source code compression.
1) It unifies the syntax for list comprehensions and for loops, which use the
same keywords (and are thus identified easily). Basically, you can then think
of a for-loop as a list comprehension which evaluates a suite instead of an
expression, and doesn't store the evaluated items, or vice versa, which at
the moment you can't, because of the difference in setup.
2) Just as I've replied to Terry J. Reed, if you find list comprehensions easy
to read, you're also bound to be able to understand what "for <expr> in
<expr> if <expr>:" does, at least AFAICT.
3) Generally, indentation, as Terry J. Reed suggested, isn't always good. If
the body of the loop is more than a few lines long (which happens more often
than not in my code), extra indentation is bound to confuse me. That's why I
use "if not <expr>: continue" at the moment, so that I don't need extra
indentation. If I could just append the condition to the loop to get it out
of the way (just as you do with a list comprehension), I save the
obnoxious "if not <expr>: continue" (which destroys my read flow of the body
somewhat too), and still get the same behaviour without any extra
(errorprone, in my eyes) indentation.
Anyway, it's fine if Guido says this is -1. I don't need to discuss this, as I
guess it's a pretty futile attempt to get people to consider this against
Guido's will. I just found this to be something I'd personally longed for for
a long time, and had time free today, so I thought I'd just implement it. ;-)
And, additionally, nobody's keeping me from making my own Python tree where I
can keep this patch for my very personal scripts where I don't need to have
interoperability. This is open source, isn't it? ;-)
--- Heiko.
More information about the Python-Dev
mailing list