5 ms·
People who gloss over this do so at your own risk. This technique is applicable for so, so many applications - even when it doesn't appear obvious at first. Fa
by vbtemp 6y ago
People who gloss over this do so at your own risk. This technique is applicable for so, so many applications - even when it doesn't appear obvious at first.
Factoring out complex control system logic into these (and related) formalisms dramatically enhances testability, substantially reduces code volume, and eliminates huge swaths of possible defects (not to mention seriously enhances formal verification and model checking). The "code" part for applications should basically be for data plumbing, and all decision-making and control logic should be factored into these.
Thanks for posting this!!
- billfruit 6y agoYes, but the heavy lifting required behind the scenes to make statecharts work seems quite elaborate, moreover it could be problematic to use blocking apis, like sockets etc with statecharts, perhaps?
- mr_olive 6y agoOn the contrary, in my experience such stateful APIs are a great use case for state machines. You just approach them differently. Instead of doing a blocking call, you introduce a "waiting for <something>" state. You leave the "blocking" state when the correct event comes, or after a timeout. And while you are waiting for the event, you don't just burn CPU cycles, but yield control quickly, so that other threads can execute in the meantime.
- chrisweekly 6y agoI don't have much experience w them yet, but found the xstate lib well-documented, and also like swizec's take: https://swizec.com/blog/when-your-brain-is-breaking-try-xstate/ https://swizec.com/blog/when-your-brain-is-breaking-try-xsta...
- adamkl 6y agoAdditionally, you can use state machines server side to track stateful processes by simply serializing the “current” state of the machine and storing it somewhere. With the next request, reload the “current” state of the machine and transition to the next based on the incoming request. Rinse/repeat.
- stainforth 6y agoCan webhooks come into play nicely with state machine models?
- billfruit 6y agoThe thing is, wont calling a blocking api block a lot of things the statchart is supposed to be doing at the same time?
- drkrab 6y agoIt’s easier when you write your application in Elixir or Erlang. Those are practically DSLs for state machines that also double as general purpose programming languages.