Generators versus Coroutines

Bryan Olson fakeaddress at nowhere.org
Sat Aug 21 10:38:33 CEST 2004


Michael Sparks wrote:
 > Bryan Olson wrote:
 > ...
 >>Have you been badly bitten by an evil co-routine?
 >
 > You appear to misunderstand what I was saying.

That could be.

 > I was not saying
 > co-routines are bad. I was saying that generators are, in my experience,
 > almost as effective.

You responded to my note that Python's generators "have a shadow
of the power of co-routines, by saying, "I've found their
simplicity useful for limiting the complexity of the
architecture."  I assumed you were saying that limiting
complexity was an advantage of Python's generators.  Perhaps I
had mis-read your meaning.  My assumption there was re-enforced
by your next sentence: "After all if any piece of software is
use for any length of time maintainability comes before
elegance."

My "Have you been badly bitten" crack was based on my reading of
your response, where I thought you disagreed my implication that
co-routines support simpler code structures and thus make programs
more maintainable.

 > This isn't attacking anything. It's saying that
 > generators really aren't as bad as it appears some people make out.
 >
 > As for network servers, it looks like the network server system based on
 > using generators to gain most of the benefits of co-routines I briefly
 > talked about (in one of the lightning talks) at EuroPython has been
 > blocked for release as open source :-(
 >
 > Your arguments in favour of co-routines for servers all hold (IME) for
 > generators as well. There is _slight_ extra obfuscation, but nowhere near
 > the level of change required for event processing.

Ah, so it seems we agree that generators result in more
obfuscation than co-routines, but in your experience the
difference is slight.  My experience is much different, and I
was trying to illustrate why that is, so readers wouldn't have
to rely just on my say-so.

 > NB. The reason I like generators is because they allow me to do
 > co-routine-type things in python with no addons.

In this thread, Bernhard Mulder showed how to do "co-routine-
type things" with Python generators, and to me the result looked
much worse than with real co-routines.  Do you have a much simpler
general method?

I do like the idea of "no addons", and that's why I'd like to
see co-routines in Python.  I'd like continuations even more,
but the Python authorities seem to value easy C-integration too
highly to allow that.


-- 
--Bryan



More information about the Python-list mailing list