PEP 289: Generator Expressions (please comment)

Holger Krekel pyth at devel.trillke.net
Mon Oct 27 10:52:48 EST 2003


Alex Martelli wrote:
> > Although most people on python-dev and here seems to like this PEP I
> > think it generally decreases readability.  The above constructs seem
> > heavy and difficult to parse and thus i am afraid that they interfere
> > with the perceived simplicity of Python's syntax.
> 
> Let's see: today, I could code:
>     sum([x*x for x in roots])
> In 2.4, I will be able to code instead:
>     sum(x*x for x in roots)

Yes, Raymond send me some private mail already and i clarified
that i don't like list comprehension syntax as well :-)

Actually i do like generator expressions *more* than list comprehensions
so i agree to your points that gen expressions do improve on the (rather
specific) list comprehensions. 

Nevertheless, i have the impression that this kind of syntax (be it list
comprehension or generator expressions) somewhat decreases the
chances for "immediate" understanding of python code without knowing 
the language much.  It's likely that you need to parse generator 
expressions in detail especially because they don't provide sharp 
visual clues like indented blocks do.  I do consider the "visual clues"
to be a strength of current python although you can always provide
examples with a language's syntax which are not readable. 

Generator expressions will probably raise the barrier to understanding
python code without having appropriate knowledge but that may very well
prove to be worth it. We'll probably find out soon so i think we don't 
need to argue a lot about it now.  IOW, i am not completly opposed 
to the PEP just a bit skeptical.  And, btw,  i appreciated very much, 
that Guido made it clear from the start that Python 2.3 would be a
maintenance release with no changes to syntax.  I am probably just
astonished at these huge syntax-threads all over python-dev :-)

have fun,

    holger





More information about the Python-list mailing list