Why developers never use state machines (2011)
1–10 of 121 posts
Re: Why developers never use state machines (2011)
#2They are not as common in software because software is one giant state machine already. Variables hold state, there is state within state (classes, composition etc). Sometimes entities in game design have explicit state machines for their behavior but that's to minimize complexity rather than due to absolute necessity
Re: Why developers never use state machines (2011)
#3Re: Why developers never use state machines (2011)
#4At the framework level they might be pretty useful, but they rarely appear at the first version, but as a result of refactoring.
Re: Why developers never use state machines (2011)
#5That being said, for some types of problems a high-latency finite state machine greatly simplifies the complexity of handling data stream consolidation efficiently. The trick is knowing when it should be avoided like in shared-state awareness problems... you know, the "lets pause the internet while I do this one op" guy we all work with sometimes... =)
Re: Why developers never use state machines (2011)
#6Re: Why developers never use state machines (2011)
#7It took more time to program than a bunch of messy if-else logic would, but it was well worth it. The knowledge that your GUI can't find itself in an invalid state is realy reasuring, and also it's preety easy to add new states/logic after you get over the initial hump.
Re: Why developers never use state machines (2011)
#8I 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 of the best examples of where state machines shine. State-machine based ImGuis lower complexity by orders of magnitude, yet, people still resist.
Re: Why developers never use state machines (2011)
#9Most text language based state machines are a mess and difficult to reason about.
FWIW I maintain a state machine library for Ruby called wicked that (IMHO) isn’t too bad, but can still get gnarly if you’re not careful.
Re: Why developers never use state machines (2011)
#10My problem with most state machines is that they are tied to your implementation language. And they are ad hoc.
An implementation programming language is itself a state machine - if you think of memory as being the states the machine can be in.
My state machine serialization supports and defines behaviour between concurrent threads and collections.
It defines a state machine between threads in async/await thread pool
Here is the serialization:
next_free_thread = 2
task(A) thread(1) assignment(A, 1) = running_on(A, 1) | paused(A, 1)
running_on(A, 1)
thread(1)
assignment(A, 1)
thread_free(next_free_thread) =
fork(A, B)
| send_task_to_thread(B, next_free_thread)
| running_on(B, 2) paused(B, 1)
running_on(A, 1)
| { yield(B, returnvalue) | paused(B, 2) }
{ await(A, B, returnvalue) | paused(A, 1) }
| send_returnvalue(B, A, returnvalue)
This defined a progression of a task on a thread and that can fork to a background task and then synchronize with a yield later on