generator/coroutine terminology

Ian Kelly ian.g.kelly at gmail.com
Mon Mar 16 10:52:48 EDT 2015


On Mon, Mar 16, 2015 at 7:39 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Mon, 16 Mar 2015 11:51 pm, Rustom Mody wrote:
>
>> It may help to read this 15 year old thread starting
>> https://mail.python.org/pipermail/python-dev/2001-June/015478.html
>> to see how many python stalwarts dont like the current state of affairs
>
> /s/dont/didn't/
>
> That's a fifteen year old thread, written before generators were introduced.
> Guido's intuition has been vindicated -- generators have proven to be a
> great and powerful feature, and the reuse of "def" for both generator
> functions and regular functions has turned out to be no more confusing in
> practice than the use of "def" for both functions and methods[1].
>
>
> The argument is that generator-producers (def-with-yield) are not like
> regular functions because calling the def-with-yield doesn't execute the
> code inside them. Given three objects:

There is another argument, which is that for functions and classes,
the descriptive keyword ("def" or "class") is the first thing you see when
reading the code. For generators, the descriptive keyword ("yield") could
be buried *anywhere* in that block. One can glance at a generator
function and fail to notice that it is a generator function. This is
the one that really bugs me about reuse of "def", although you are
correct that this is a case where practicality has won over purity.



More information about the Python-list mailing list