Computers ARE state machines and the primary purpose of a programming language is to help humans manage all this state.
I’d argue the best way to do that is to write stateless code and let the compiler figure out how to make it fast
Why developers never use state machines (2011)
81–90 of 121 posts
Re: Why developers never use state machines (2011)
#82Where is the line between a state machines and object-oriented? One encapsulates some state and provides a set of messages to modify it. The other encapsulates some state and provides a set of transitions to change it.
Re: Why developers never use state machines (2011)
#83Where is the line between a state machines and object-oriented? One encapsulates some state and provides a set of messages to modify it. The other encapsulates some state and provides a set of transitions to change it.
Re: Why developers never use state machines (2011)
#84Re: Why developers never use state machines (2011)
#85Re: Why developers never use state machines (2011)
#86I'm an EEE, and one of the strange things I've noticed is that, for whatever reason, people from a CompSci background is really, really have trouble building and understanding even simple state machines. I suspect this unintuitiveness is the main reason why we don't see more state machines, as even in the case where they're an optimal solution many SWEs will shy away from them. Locally-rendered UIs are probably one o…
The only time I've ever used a state machine in real code is when parsing text one token at a time or something like that. It's a useful skill to remember for those situations. And this kind of problem is very over-represented in SWE interviews.
Re: Why developers never use state machines (2011)
#87Earlier quoted context omitted.
They do not scale well. It is why Elm-style explicit message passing UIs are not popular. State machines work for state localised to a widget, but the moment you scale up to something moderately complex (spreadsheets, datagrids, forms etc.), your diagrams balloons in size. For non safety-critical applications, it is better to have implicit state and potential bugs than to have your engineering team waste time proving…
> but the moment you scale up to something moderately complex (spreadsheets, datagrids, forms etc.), your diagrams balloons in size I'm no CS major. But isn't that what Hierarchical state machines are supposed handle? Or was that all hat no cattle and/or a lost knowledge when UML style stuff got tossed away?
Maybe there's some math-ey way of saying everything we do is an FSM, but I don't think of it that way.
Re: Why developers never use state machines (2011)
#88This is a strange take. Every last program ever written is a state machine. The number of possible states a program represents is normally very, very large, and the transition rules are very complicated and often mixed up with, e.g., multiplier circuits. So we use familiar programming languages instead, which help to organize it all. A program emulating another state machine tends to raise the question why the (or an…
Here is a kind of bridge from the articles POV to yours: As the OP points out, state machines are very hard to develop by stepwise refinement. A "general solution" to that problem is...the universal Turing machine--a state machine which can emulate any other state machine. However, its really hard to program a Turing machine, so we invented assembly language, which is really hard to program, so we invented higher-lev…
So I guess that making a state machine involves clearly separating the write-protected parts that make it from the rest of the program, and forbidding tampering ?
Also, all computing is not (directly) state machines or even Turing machines : quantum computing and generally analogic computing come to mind.
P.S.: Also, seems like (because of that restriction ?) you cannot have multithreading inside a state machine ?
Re: Why developers never use state machines (2011)
#89I'm an EEE, and one of the strange things I've noticed is that, for whatever reason, people from a CompSci background is really, really have trouble building and understanding even simple state machines. I suspect this unintuitiveness is the main reason why we don't see more state machines, as even in the case where they're an optimal solution many SWEs will shy away from them. Locally-rendered UIs are probably one o…
Usually your state is more complicated than just one enum. You'll have counters, buffers, etc. The only time I've ever used a state machine in real code is when parsing text one token at a time or something like that. It's a useful skill to remember for those situations. And this kind of problem is very over-represented in SWE interviews.
Re: Why developers never use state machines (2011)
#90Earlier quoted context omitted.
Usually your state is more complicated than just one enum. You'll have counters, buffers, etc. The only time I've ever used a state machine in real code is when parsing text one token at a time or something like that. It's a useful skill to remember for those situations. And this kind of problem is very over-represented in SWE interviews.
Well yes, because state machines are identical to regular expressions... though regular expressions tend to be used quite a lot ?