yield_all needed in Python
Steve Holden
steve at holdenweb.com
Tue Mar 1 17:46:49 EST 2005
Douglas Alan wrote:
> David Eppstein <eppstein at ics.uci.edu> writes:
>
>
>>In article <lcacpnxp8s.fsf at gaffa.mit.edu>,
>
>
>> Douglas Alan <nessus at mit.edu> wrote:
>
>
>>>>Cetainly, if <yield_all
>>>>iterator> == <for i in iterator: yield i>, I don't see how anything
>>>>is gained except for a few keystrokes.
>
>
>>>What's gained is making one's code more readable and maintainable,
>>>which is the one of the primary reasons that I use Python.
>
>
>>I don't see a lot of difference in readability and maintainability
>>between the two versions.
>
>
> In that case, your brain works nothing like mine.
>
Well, the fact that different people's brains work differently is hardly
worth remarking in this day and age. Hence my (and other people's)
questioning of the word "needed" in the title of this thread.
Guido has generally observed a parsimony about the introduction of
features such as the one you suggest into Python, and in particular he
is reluctant to add new keywords - even in cases like decorators that
cried out for a keyword rather than the ugly "@" syntax.
In my opinion that is a good thing mostly, not only because it avoids
code breakage (which can't possibly be bad) but also because it tends to
limit the number of ways that different programmers can express the same
idea.
I suspect this is why people have suggested that you were "only going to
save a few keystrokes". Despite your feeling that yield_all makes the
intent of the code more obvious there seems to be a majority in favor of
the simpler expression of the idea with a yield in a loop.
If you think there's a genuine chance this could be usefully added to
Python the solution is obvious: write and submit a PEP.
regards
Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005 http://www.pycon.org/
Steve Holden http://www.holdenweb.com/
More information about the Python-list
mailing list