Generators versus Coroutines
nomail at nomail.nomail
Mon Aug 16 19:52:39 CEST 2004
> It really was never an issue of "Python can't handle this." it was
> more of an issue of "Python should more openly support this." I am
> championing generators because they make programming SO much easier in
> cases, and people really just don't use them outside if list
> generation, which saddens me.
Coroutines are much more powerful than Python's generators and
they can be easily abused to create unstructured
"goto"-like programs thus I assume it would still be a good idea
to put most effort into your architecture and it's
underlying execution model regardless of what you finally
use to keep state: coroutines, threads, (nested) generators.
Try to hide the implementation if you can.
Nesting generators works, but I have to admit
it's (probably) not very elegant.
I would also prefer coroutines for simulation and games as
a module similar to thread/threading.
I think Michael Jackson wrote a converter for COBOL
in the 70s, which would "invert" active entities into
ordinary functions keeping their state in ordinary data structures.
This can certainly be done in Python too.
Maybe this helps.
P.S. Many programming languages do not even have
support for "generators", e.g. Java
Ha! Maybe @decorators are the solution ! ;-)
More information about the Python-list