3 ms·
I assume I'm missing that this a joke, it's honestly hard for me to tell. But in the conclusion, the author talks about actually making this work by providing
by anymouse123456 3y ago
I assume I'm missing that this a joke, it's honestly hard for me to tell.
But in the conclusion, the author talks about actually making this work by providing a context object to hold all of the intermediate state and providing this context object to the callee.
Once this is required, how does this approach compare to simply using an external iterator?
Seems to me like an iterator solves the lion's share of the problem here. It moves the state into the caller's stack (or above them), it's easy to understand, simple to implement and doesn't involve unenclosed and context-dependent macros.
- syncurrent 3y agoProto-Activities have this context to store the state in the caller. https://github.com/frameworklabs/proto_activities https://github.com/frameworklabs/proto_activities
- ajross 3y ago> Seems to me like an iterator solves the lion's share of the problem here. Iterator APIs are indeed aimed at the same kind of problem, but they're not the same solution. And often they're harder to write. If you have a component with a big list of stuff, it's generally easier to write and understand the idea of "iterate over my big list of stuff and emit one item at a time to my consumer" than it is "what state do I need to remember such that when I get called again I can emit the correct next item given the one I just emitted?". Coroutines are a way of expressing the former. Iterators are the latter. If all you do is write the outer loop, iterators are absolutely just as good. If you need to write the iterator itself, it's more of a discussion.
- btilly 3y agoWhy would you assume that this is a joke? C (particularly back when this was written) was a low level language. You could not simply use an external iterator - they didn't exist. And if you try to roll your own, you'll wind up dealing with a lot of complications around resource management in a language which lacks basic memory management. But the proof is in the pudding. Back then it was common to want to telnet into a Unix machine from Windows. And the only two solutions that worked well enough to consider were installing Cygwin, or installing PuTTY. Cygwin was better if you needed a Unix environment on your Windows machine. Otherwise PuTTY was your answer. As the article comments, PuTTY was written with this technique. When you've solved a problem that a lot of people had, and your solution is widely acknowledged as the best one out there, people get interested in how you think it should be solved. Which is why this article interested me when I first saw in many years ago on Slashdot. So absolutely not a joke.