Re: yield_all needed in Python
From: David Eppstein (eppstein_at_ics.uci.edu)
Date: 03/01/05
- Next message: Steve Holden: "Re: Why does interpreter flub"
- Previous message: Peter Hansen: "Re: Why does interpreter flub"
- In reply to: Douglas Alan: "Re: yield_all needed in Python"
- Next in thread: Douglas Alan: "Re: yield_all needed in Python"
- Reply: Douglas Alan: "Re: yield_all needed in Python"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 01 Mar 2005 12:14:45 -0800
In article <lcacpnxp8s.fsf@gaffa.mit.edu>,
Douglas Alan <nessus@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. And if yield_all is going to expand into the
loop, anyway, I'd prefer to make that obvious by using the for-loop
version, rather than using a keyword and pretending that passing the
iterators on has no overhead.
If we're talking about machinery behind the scenes to shortcut chains of
yield_all's, so that the time to pass items up through the chain is
smaller than it would be in the for-loop case, I'd think that would be a
better reason for a keyword, because it's not something that can be done
very easily without one in the current language. I don't know how to
make such shortcutting machinery faster than logarithmic in the worst
case (taking into account the possibility that multiple generators could
have yield_all's to the same iterator) but I think it could be made
nearly constant time in most situations. On the other hand, I'm not
convinced that this would be needed frequently enough to warrant the
complexity of trying to optimize it.
-- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/
- Next message: Steve Holden: "Re: Why does interpreter flub"
- Previous message: Peter Hansen: "Re: Why does interpreter flub"
- In reply to: Douglas Alan: "Re: yield_all needed in Python"
- Next in thread: Douglas Alan: "Re: yield_all needed in Python"
- Reply: Douglas Alan: "Re: yield_all needed in Python"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|