Live data from Hacker News

Statecharts: hierarchical state machines

statecharts.dev

81–90 of 91 posts

Re: Statecharts: hierarchical state machines

#81
The hierarchy capability of Statecharts sounds amazing. A couple of questions: 1. My intended use case is a robot with code written in C/C++. Should I use the translator the search engines suggest? Or?

2. I did come across Tinyfsm (https://digint.ch/tinyfsm/). Any thoughts on that?

Re: Statecharts: hierarchical state machines

#82
I love XState. It has solved so many problems in quite a few codebases for me, most recently it has become the backbone of a voice app I'm building for the banking sector. Thank you for all the time and effort you put into making it great.

I blogged[0] a bit about my experience with Finite State Machines, and about the architecture we landed on with XState and Mastra (although since publishing we have swapped to Pipecat).

[0] - https://blog.davemo.com/posts/2026-02-14-deterministic-core-...

Re: Statecharts: hierarchical state machines

#83

2 hours and not a single comment yet?! At one point, Statecharts seemed to be getting traction in the frontend/UI ecosystem, albeit tiny traction. Leveraging state machines (and particular Statecharts, which is basically compositions of state machines) for UI interactions makes complex flows so much easier to reason about! However, seems the traction eventually disappeared for unknown reasons, sadly. If this is the f…

Not sure about the charts themselves, but it helps structure code and logic better if a clear description of possible states (of phenomena) is provided and reasoned about.

Naturally, as the author notes, we are using states in our programs. Three kinds at least

- current program state in the complex space-of-states the program can have - most properties (and vars) are expect to undergo several states, and enumerable denotes a state. - every program traversing a graph for something, essentially runs a state machine of some sort

Indeed a user interface can benefit from having a FSM run it, given interfaces guide the end-user through predefined states from which he navigates into other states (which show/hide a set of widgets and wire them with data).

Re: Statecharts: hierarchical state machines

#84
post #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

This would be the closest: https://github.com/GnomesOfZurich/scxml/

Re: Statecharts: hierarchical state machines

#85
post #66

One thing usually skipped in primers: history pseudo-states (H, H ) make a statechart formally non-deterministic from outside. The pitch is "current state is a pure function of inputs" — history breaks that. Entering a parent via `H` puts you in whichever child was active last, so the same event from the same outer state can land you in two different inner states. That latent "last-active child" IS state, just state…

hm "inputs" can refer to just current and future inputs --- or it refers to the totality of inputs, including the inputs leading up to "here". in the latter interpretation the machine is perfectly deterministic. and the "deep history" pointer simply is part of the state machine.

Fair pushback - I was loose with "inputs". Formally yes: if you fold input history into the state itself, every deterministic FSM stays deterministic, H pseudo-states included. The narrower point I was trying to make is that the diagram isn't a complete representation once H is involved. From the practical reading of statecharts - "look at the chart and predict next state given a transition" - H breaks that without showing what it added. The latent state exists but isn't drawn. So the formalism is sound; the visualization is incomplete.

Re: Statecharts: hierarchical state machines

#86
post #67

One thing usually skipped in primers: history pseudo-states (H, H ) make a statechart formally non-deterministic from outside. The pitch is "current state is a pure function of inputs" — history breaks that. Entering a parent via `H` puts you in whichever child was active last, so the same event from the same outer state can land you in two different inner states. That latent "last-active child" IS state, just state…

Going solely off your description of the scenario; couldn’t you trivially model any history (H,H) node as two nodes —> (A, H’) —-> (H’, H) —> (H, B), and have it be deterministic again I’m essentially thinking of H’ as a write-ahead-log prefixing any node

Yes, you can — that's effectively what "expanding" the chart looks like. With a parent of N children you need N target nodes (one per possible "last-active" child) with deep history the cardinality is the size of the subtree's leaf set, which is exponential in nesting depth. That's exactly the explosion flat FSMs hit when you compose them — and the reason Harel introduced H notation in the first place, to elide it. So determinism is recoverable, just at the cost of the very property state charts were designed to deliver.

Re: Statecharts: hierarchical state machines

#87
post #71
post #54

Earlier quoted context omitted.

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.

Well, the word "machine" by itself is even more established, and it isn't compatible with describing diagrams (that routinely don't represent machines) as machines.

Re: Statecharts: hierarchical state machines

#88

Earlier quoted context omitted.

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 pers…

Thanks to the both of you. I have always just stuck to plain old Control Flow Diagrams, which can be quite tricky to get all the nuances of a FSM. Always been interested to commit to using Statecharts or PetriNets, but I think the usefulness of concurrency tips it over the edge… To Amazon I go
Post reply on HN