Sujet : Re: Threads across programming languages
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.lang.c++ comp.lang.cDate : 02. May 2024, 00:05:50
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v0uhse$3e0vg$4@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : Pan/0.155 (Kherson; fc5a80b8)
On Wed, 01 May 2024 21:00:19 GMT, Scott Lurndal wrote:
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>
Callbacks can be a clunky way of event handling, since they force you to
break up your logic sequence into discontinguous pieces. This is why
coroutines have become popular, since they keep the logic flow together.
Callbacks work just fine, as the logic for submitting a request
is quite different from the logic for completing a request ...
They are typically part of the same logic flow. Having to break it up
into separate callback pieces can make it harder to appreciate the
continuity, making the code harder to maintain. It can also require
more code.
Have a look at the two versions of the “rocket launch” example I
posted here
<
https://github.com/HamPUG/meetings/tree/master/2017/2017-05-08/ldo-generators-coroutines-asyncio>:
not only is the callback version about 30% bigger, it is also harder
to understand.
Sure, it’s a toy example (44 versus 57 lines). But I think it does
illustrate the issues involved.