Get the latest tech news
Philosophy of Coroutines (2023)
[Simon Tatham, initial version 2023-09-01, last updated 2025-03-25] [Coroutines trilogy: C preprocessor | C++20 native | general philosophy ] I’ve been a huge fan of coroutines since the mid-1990s. I encountered the idea as a student, when I first read The Art of Computer Programming.
That’s especially true if they’re based on my C preprocessor system, because a person coming fresh to a function in that style is going to see some weirdo crReturn macro, look up the definition, be further baffled (it’s fairly confusing if you don’t already recognise the trick), and probably conclude that I’m throwing obstacles in their path on purpose! An effect of that was that you couldn’t open a PuTTY window and immediately start typing the first shell command you wanted to run in your session, even if you knew that authentication was going to succeed without needing any prompts (say, because you were using an SSH agent). Incidentally, yes, I know, there’s another special case that my code doesn’t handle: if the input iterator has no values, then the example version of cyclic_pairs shown here will raise StopIteration, when perhaps you’d prefer it to silently generate an empty output list.
Or read this on Hacker News