[Twisted-Python] Soon to be not-a-newbie?
mithrandi at mithrandi.za.net
Fri Jan 25 19:46:28 EST 2008
* Nitro <nitro at dr-code.org> [2008-01-25 23:42:41 +0100]:
>>> the recent spate of inlineCallbacks-related posts alarms me.
> Why? Using inlineCallbacks just helps writing convenient syntax utilizing
> deferreds. If you ever wrote code which uses lots of deferreds, you know
> that the code is (visually) lacking a decent structure. It's just not the
> way you think and makes things hard to read. inlineCallbacks just turns
> this into a nice, linear piece of code again (linear not to be confused
> with synchronous!).
The problem I have with this is that I find that it actually obscures
the flow of the code and data. Most deferred operations have no need to
be serialized, and shouldn't be; the linear nature of
inlineCallbacks-style makes it very easy to accidentally serialize
operations that could otherwise run in parallel instead. Even if you
write the generator correctly, it's not as obvious what the actual flow
is since it has been crunched into a linear-looking function. Finally,
it is extremely hard to unit test a generator using inlineCallbacks, as
there is no easy way of resuming the generator at certain points with
certain state to test each part of the generator.
I'm not necessarily convinced that inlineCallbacks is always bad, but it
certainly leads to subtle traps in most cases, while providing little
real benefit (despite the perceived benefit).
mithrandi, i Ainil en-Balandor, a faer Ambar
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 197 bytes
Desc: Digital signature
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20080126/a9207e9f/attachment.pgp
More information about the Twisted-Python