Please comment on Draft PEP for Enhanced Generators

Jonathan Hogg jonathan at onegoodidea.com
Wed Jan 30 20:21:37 CET 2002


On 30/1/2002 8:48, in article a38c1u$945$1 at bob.news.rcn.net, "Raymond
Hettinger" <othello at javanet.com> wrote:

> I have written a draft PEP summarizing proposed enhancements to generators:
> http://users.javanet.com/~othello/download/genpep.htm

Hi Raymond,

My comments:

* New lazy builtins - yup. Except, I'm not convinced of using sys.maxint
  in index(). I know that's a big number, but I still get the worrying
  feeling that limiting the upper bound is a bad idea. Python 2.2 will
  automagically switch to using longs if you hit maxint, but here it will
  just terminate without any obvious error message or idea as to why.

* I also prefer using 'indexed' to 'index'. It just seems to read better
  to me. Also, I use 'index' as a variable name all the time and wouldn't
  want the name clash.

* I'm a big fan of generator comprehensions for symmetry, but I must admit
  that I'm not sure they're worth adding new syntax for.

* I'm not convinced about the suggested mechanism for implementing consumers
  via re-using the yield keyword with some magic. It just doesn't feel right
  to me. It looks too arbitrary [crisps shouldn't melt, they should crunch].
  I think you should present an alternative or two. Perhaps introducing new
  syntax for consumers, maybe:

    def foo():
        while 1:
            x = accept
            print x

  or some such. Perhaps you should also provide a stronger argument as to
  why consumers would be a valuable addition. Picking something from the
  standard library and re-writing it is always good. Have you tried the
  "nine out of ten cats understood what this code sample did" test?

* Is there a reference implementation for the consumer modification?

Jonathan




More information about the Python-list mailing list