Re: yield_all needed in Python

From: David Eppstein (eppstein_at_ics.uci.edu)
Date: 03/01/05


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/


Relevant Pages

  • Re: Code Behind vs not
    ... maintainability are certainly high priority, ... Because truly efficent code in NEVER readable, ... > understanding is a result of readability. ... > long time delphi programmer, I prefer VS to borland in this arena). ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Code Behind vs not
    ... > maintainability are certainly high priority, ... >> The best code is both readable and maintainable and balances efficency. ... >> understanding is a result of readability. ... >> long time delphi programmer, I prefer VS to borland in this arena). ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: FizzBuzz
    ... the ultimate of maintainability, something like this is likely to be ... makesub fizz? ... array, ... And if you want readability, ...
    (comp.lang.forth)
  • Re: Dim a byte array.
    ... > coding techniques across the years. ... the first code I posted was in response to Randy saying it ... As to maintainability or even readability... ... > maintainability were apparently not high on his list of concerns.... ...
    (microsoft.public.vb.general.discussion)
  • Re: Highly used programs: any better replacements out there?
    ... The maintainability issue has been made very clear (well, ... But where is the readability concern/advantage? ... For IBM-MAIN subscribe / signoff / archive access instructions, ... send email to listserv@xxxxxxxxxxx with the message: GET IBM-MAIN INFO ...
    (bit.listserv.ibm-main)