News for hackers. Stuff that matters.
Re:C++ Coroutines Do Not Spark Joy by jayd16 on Friday April 05, 2024 @02:38AM (#39939326)
They're not different though, right? Just two ways to think about what it means to return, no? How can you return a value without returning control to read that value? They're the same.

Still, I don't think iterators and coroutines are necessarily the same. You can imagine a coroutine that doesn't return a value and only happens to share a thread or something.

Re:C++ Coroutines Do Not Spark Joy by ezekiel68 on Friday April 05, 2024 @02:51AM (#39939404)
Regardless of the underlying mechanism that make them both work, programmers generally have a vastly different conception of yielding (that is, 'producing') a generated value as opposed to yielding (that is, 'ceding') execution time to the OS or a virtual machine.
Re:C++ Coroutines Do Not Spark Joy by LoganDark on Friday April 05, 2024 @02:52AM (#39939411)
Right, difference between yield as in "crop yield" and yield as in "yield right of way".
Re:C++ Coroutines Do Not Spark Joy by LoganDark on Friday April 05, 2024 @02:41AM (#39939346)
That's the thing, since either one can be implemented in terms of the other, people conflate iterators/generators with coroutines as you've mentioned because they're easily interchangeable.
Re:C++ Coroutines Do Not Spark Joy by int_19h on Friday April 05, 2024 @06:51AM (#39940868)
This is functionally identical to yielding a dummy value. If the language has a unit type (e.g. a 0-ary tuple) then you just use a value of that type.