4 ms·
How would PEP 380 improve Monocle style programming? http://www.python.org/dev/peps/pep-0380/ http://www.python.org/dev/peps/pep-0380/ I don't have enough exp
by equark 16y ago
How would PEP 380 improve Monocle style programming?
http://www.python.org/dev/peps/pep-0380/ http://www.python.org/dev/peps/pep-0380/
I don't have enough experience to really understand.
- rhettinger 16y agoMonocle works by wrapping a single generator and translating each yield-statement into a hand-off to the event loop or reactor and resuming when the value of the deferred becomes known. Since the code is confined to a single generator, it's not easy to factor-out the steps into subroutines. PEP 380 provides a syntax for having sub-generators which can potentially be used to factor your code into smaller, reusable components. PEP 380 is about providing better support for nested generators including the scaffolding with try/finally, g.send(), g.next(), g.throw(), and g.close(). In short, PEP 380 lets you nest, and nesting lets you factor your code.