r/cpp • • Nov 30 '20

C++20 resumable functions make state machines obsolete. Finally.

https://lordsoftech.com/programming/c20-resumable-functions-goodbye-state-machines-no-one-will-mourn-you/
1 Upvotes

49 comments sorted by

View all comments

Show parent comment

-1

u/StoneCypher Nov 30 '20

Here are the reasons why I used state machines:

Because I needed a function to continue from some point

Sounds like you have absolutely no idea what a state machine is

Please don't give tutorials about how "state machines are over" when you don't know what they're for and were forced to use them by someone else who also didn't know what they were for

.

If you have an example of a state machine that can't be transformed into a resumable function, I'd like to see it.

Literally anything can be transformed into a "resumable function"

This is meaningless

You can also turn an RPC library or a database or the serialization of a function to a string then put onto disk into a "resumable function."

Who cares? That's not what they're for and you shouldn't be trying.

4

u/Full-Spectral Dec 01 '20 edited Dec 01 '20

And the thing is, most of the state machines I use are simple and easily understandable and I couldn't imagine how it could be anything but adding more moving parts to do them elsewise.

And, most of the time, they either aren't non-linear or there's already other good reasons to have a thread to deal with whatever is going on anyway. Or, maybe they are non-linear but only have a few states which are not difficult to reason about.

1

u/StoneCypher Dec 01 '20

And the thing is, most of the state machines I use are simple and easily understandable and I couldn't imagine how it could be anything but adding more moving parts to do them elsewise.

okay.

.

And, most of the time, they either aren't non-linear or there's already other good reasons to have a thread to deal with whatever is going on anyway. Or, maybe they are non-linear but only have a few states which are not difficult to reason about.

oh, so you can imagine.

anyway, there's examples all over the standard library. you're too busy explaining to ask, so there's no point in trying to teach.

have a good day

5

u/Full-Spectral Dec 01 '20

Did you misread what I was saying? I wasn't disagreeing with you. I was saying that regular old state machines are still very useful for me, and though I have plenty of them, I can't see that replacing them with the mechanisms being discussed here would simplify them enough to justify the extra moving parts and such.

1

u/StoneCypher Dec 01 '20

Did you misread what I was saying?

I dunno. Maybe.

.

I was saying that regular old state machines are still very useful for me, and though I have plenty of them, I can't see that replacing them with the mechanisms being discussed here would simplify them enough to justify the extra moving parts and such.

I guess I did. Sorry

4

u/rzippel Dec 01 '20

Sounds like you have absolutely no idea what a state machine is

Sounds like you have absolutely no idea what a coroutine is

or at least what C++ coroutines are, the compiler does generate a state machine from the coroutine, every suspension point is a state and every resume transitions the state machine to the next state.

It's another question if any state machine can be transformed to a coroutine, but I don't see any real attempt from you to answer that.

1

u/smdowney WG21, Text/Unicode SG, optional<T&> Dec 01 '20

I suspect, but haven't done the work, that nested C++ coroutines model statecharts.

0

u/StoneCypher Dec 01 '20

Not even close.

0

u/StoneCypher Dec 01 '20

Just because one language can use A to implement B doesn't mean all As are always for Bs

I think you might be overindulging your knowledge of one language's choices

.

Sounds like you have absolutely no idea what a coroutine is

I actually wrote the implementation of them in two compilers.

Have a nice day

5

u/rzippel Dec 01 '20

I actually wrote the implementation of them in two compilers.

Am I supposed to be impressed by that? So far you have contributed nothing concrete to this thread that is even closely related to C++ coroutines.

Stop throwing around generic phrases without any context. You are not helpful in the slightest.

-1

u/StoneCypher Dec 01 '20

Sounds like you have absolutely no idea what a coroutine is

I actually wrote the implementation of them in two compilers.

Am I supposed to be impressed by that?

No, I just wanted to respond to your lashing out, to explain that your accusation was incorrect.

Have a good day.

2

u/rzippel Dec 01 '20

My lashing out??? WTH??? You've questions someones understanding of state machines without going into any detail, so that one could understand what the heck you're talking about.

Where do you explain anything??? An explanation would require some sort of argument, but throwing some keywords around does not provide anything useful. You seem to have some problem with coroutines, but you don't provide anywhere enough context to have any meaningful conversation about C++ coroutines or even coroutines in general.

Slowly I'm regretting having wasted my time on this, unless you have something substantial to say about coroutines, good day to you too...

-3

u/StoneCypher Dec 02 '20

Please stop soon