[Python-ideas] Revised revised revised PEP on yield-from

Guido van Rossum guido at python.org
Tue Feb 17 05:40:47 CET 2009


On Mon, Feb 16, 2009 at 7:05 PM, Guillaume Chereau <charlie137 at gmail.com> wrote:
> But what I don't really like with it, is that when you start to write
> coroutines, you have to use yield every time you call an other
> coroutine, and it make the code full of yield statement ; the proposal
> if adopted would make it even worst.

I don't see how the proposal would make it *worse* (assuming that's
what you meant, and "worst" was a typo).

Coroutines make my head hurt more than metaclasses, but I see value in
the proposal besides coroutines. Recursive generators are pretty
calling and the "for x in A: yield x" idiom gets tiresome to read and
write. Personally I care more about having to mentally parse it and
realize "oh, it's a recursive generator" than about the extra typing
it requires (only seven characters more :-).

The mental parsing is a relatively big burden: the whole first line
gives no indication that it's a recursive iterator, because "for x in
A:" could start a loop doing something quite different. Your
code-reading brain has to find the correspondence between the loop
control variable of the for-loop header and the variable yielded in
the loop body, see that nothing else is going on, and *then* it can
draw the conclusion about the recursive generator. Once learned,
"yield from" is a mental shortcut that saves your code-reading brain
time and effort, which in turn helps understanding the larger picture
of which this construct is a part -- you don't have to push anything
onto your mental stack to see what's going on with "yield from".

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



More information about the Python-ideas mailing list