Live data from Hacker News

Statecharts: hierarchical state machines

statecharts.dev

71–80 of 91 posts

Re: Statecharts: hierarchical state machines

#71
post #54

Earlier quoted context omitted.

I think it's either "hierarchical state machines" or just "statecharts", otherwise it's a bit like saying ATM machine or CC card.

Perhaps, but I object to the "machine" phrasing. Ordinary finite state "machines" (without hierarchy) aren't machines either, they are just diagrams of something that could be a machine or something else.

finite state machine (FSM)

state charts (FSM with history pointers)

pushdown automaton (FSM with a stack)

turing machine (FSM with a tape)

the terminology is well established.

Re: Statecharts: hierarchical state machines

#72

Glad to see statecharts still getting attention! I created XState, a JS/TS library for authoring, executing, and visualizing state machines/statecharts: https://github.com/statelyai/xstate I've been working on it for 10+ years. The main thing I've learned is that statecharts are most valuable when they're treated as executable behavior, not just documentation. That doesn't mean you need to use them everywhere or mode…

You were the reason I first discovered state machines! This was a talk I gave at Laracon that was my stab at distilling my thinking about State Machines, State Charts etc. https://www.youtube.com/watch?v=1A1xFtlDyzU

I loved this talk!

Re: Statecharts: hierarchical state machines

#73

Earlier quoted context omitted.

With all respect to xstate, if you don't need complex nested state machines, you should check out robot3.js. The automatic TS type inference makes it pretty handy for the spots where you want a bit of state machine logic.

There is also @xstate/store for simple event-driven stores and atoms; just as simple as Zustand + Jotai: https://stately.ai/docs/xstate-store

I’m a big fan of @xstate/store!

Re: Statecharts: hierarchical state machines

#75

"No statechart will survive contact with real world applications". I mean, when you have external dependencies, multilayer protocols, multithreading, perf requirements, the state will becomes an ugly mess. One can only dream of a clean statechart.

Sometimes the complexity is unavoidable and you have to pick the lesser of many evils. Oftentimes complexity management is trying to model the system in such a way that the complexity moves to the area which is most easily understood. It doesn't make the system less complex, only easier to reason about and maintain. State-oriented design is just a (very powerful) tool in the toolbox. Even when I haven't actually used…

I agree, we try to think in terms in state machine. Just complaining that somehow this is not good enough, in practice we need to add random flags, and it is not clear how to separate the multitude of separate state machines all active at the same time.

Re: Statecharts: hierarchical state machines

#76

Glad to see statecharts still getting attention! I created XState, a JS/TS library for authoring, executing, and visualizing state machines/statecharts: https://github.com/statelyai/xstate I've been working on it for 10+ years. The main thing I've learned is that statecharts are most valuable when they're treated as executable behavior, not just documentation. That doesn't mean you need to use them everywhere or mode…

Since you’re in the know, do you have any opinion on Petri Nets?

I’m not the GP, but I think petri nets are awesome. At least they’re a great way to represent and visualize many systems. Statecharts I find tricky by comparison. For a simple example, imagine you’re making a game and the player has to talk to three people in any order before moving to the next stage. this is very easy to represent as a petri net. (you just need three places and have a token in each one represent having talked to the necessary person.) But I think it corresponds to 8 separate states in an FSM (or statechart? not sure). Which just seems overly complex for a simple situation like this

Re: Statecharts: hierarchical state machines

#77
We have been using statecharts at our company for all business processes after I wrote an interpreter for them inside Postgres.

It has been a great experience so darn it makes processes very resilient against change and very easy to come back to after years.

The library is open source too:

https://github.com/kronor-io/statecharts

Re: Statecharts: hierarchical state machines

#78

Earlier quoted context omitted.

Since you’re in the know, do you have any opinion on Petri Nets?

I’m not the GP, but I think petri nets are awesome. At least they’re a great way to represent and visualize many systems. Statecharts I find tricky by comparison. For a simple example, imagine you’re making a game and the player has to talk to three people in any order before moving to the next stage. this is very easy to represent as a petri net. (you just need three places and have a token in each one represent hav…

> But I think it corresponds to 8 separate states in an FSM (or statechart? not sure)

In a conventional FSM yes but not a statechart. Statecharts support parallel regions within a single state. You’d have 3 regions for your example: one waiting for each person. There would be 4 states total: one to wait on each person, each in its own region, plus the superstate. The superstate would exit when all 3 “waiting for person ” sub states exited, independent of their sequence.

I’m with you on Petri nets though, very helpful for modelling concurrent behaviour.

Re: Statecharts: hierarchical state machines

#79
When working on a project https://github.com/xlnfinance/xln (a financial account network between entities) I stumbled upon a problem that you need a way to emulate a real network deterministically. Then i realized every blockchain is just replicated state machine so why dont we encapsulate every user node into Runtime->Entity->Account hierarchy of 3 state machines. Each outer machine fully controls the inner one. Like "blockchain inside blockchain" with different consensus modes.

Then I googled for "hierarchical state machines" and found statecharts. These two ideas are somewhat similar so here are my 2cents. Imo more software should use hierarchies of state machines to fight the worst class of bugs with non-determinism.

Re: Statecharts: hierarchical state machines

#80

Glad to see statecharts still getting attention! I created XState, a JS/TS library for authoring, executing, and visualizing state machines/statecharts: https://github.com/statelyai/xstate I've been working on it for 10+ years. The main thing I've learned is that statecharts are most valuable when they're treated as executable behavior, not just documentation. That doesn't mean you need to use them everywhere or mode…

nice thanks. been looking for a rust equivalent
Post reply on HN