Live data from Hacker News

Statecharts: hierarchical state machines

statecharts.dev

21–30 of 91 posts

Re: Statecharts: hierarchical state machines

#21
Well, this is used in the automotive domain for long time now. Look at matlab/simulink: you can draw your algorithm as a state machine and generate the code out of it. Recently I implemented a state machine to manage a quite complex react component, who moves from one visual state to another through some css transitions. It’s not a difficult state machine, but I think people are not so well versed in it.

Re: Statecharts: hierarchical state machines

#22

"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.

I’ve used state charts in multi-billion legacy apps and they’ve stayed quite clean.

Just don’t use one state chart for everything. Just like any data structure, use multiple of them scoped appropriately

Re: Statecharts: hierarchical state machines

#23

Well, this is used in the automotive domain for long time now. Look at matlab/simulink: you can draw your algorithm as a state machine and generate the code out of it. Recently I implemented a state machine to manage a quite complex react component, who moves from one visual state to another through some css transitions. It’s not a difficult state machine, but I think people are not so well versed in it.

I assume game engines might already have this or sophisticated version of this already implemented.

Re: Statecharts: hierarchical state machines

#24
I've tried to use state charts for frontend development a couple of times, but bounced off. IIRC, I was using xstate with vue, and I found that they were hard to retrofit to existing systems, and where I tried, I found that the boundary between the part of the system controlled by xstate and the rest of the system problematic. It felt like it would work better with everything "inside" the statechart, but that's a big lift for an existing codebase.

Re: Statecharts: hierarchical state machines

#25

Well, this is used in the automotive domain for long time now. Look at matlab/simulink: you can draw your algorithm as a state machine and generate the code out of it. Recently I implemented a state machine to manage a quite complex react component, who moves from one visual state to another through some css transitions. It’s not a difficult state machine, but I think people are not so well versed in it.

I assume game engines might already have this or sophisticated version of this already implemented.

Sure. State machines are often useful.

A general framework is I think more rarely useful.

Unreal Engine is a popular game engine and it seems to contain dozens of different state machine frameworks.

Re: Statecharts: hierarchical state machines

#26

"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.

Hierarchical state machines are common in hardware development. I've also used them for embedded systems, and dug my way out of spaghetti nightmares in distributed systems by reworking a system into a set of state machines. Is it clean? Not always, it gets messy. On the other hand it is deterministic and traceable to specifications. Specifications as state machines can be easier understood and shared than raw code or…

[deleted]

Re: Statecharts: hierarchical state machines

#27

I wonder if it's possible to combine statecharts with durable execution engines like Temporal, DBOS, Restate, etc. At work we use Cloudflare Workflows for managing onboarding and payment workflows. It generates flowchart diagram that is useful for quickly reasoning about what the workflow does, which I guess is what statecharts is trying to achieve.

When you say "it generates flowchart diagrams…" what exactly is generating them? Is it built into cloudflare workers or is it something your team created?

Re: Statecharts: hierarchical state machines

#28
I have used nested state machines for a while now and they are really good if you have realtime needs, e.g. controlling motors, animations, audio/video playbsck and so on.

The statemachine itself also forces you to think about which transitions between which states are possible and whst you may need to consider when such a state change happens.

Re: Statecharts: hierarchical state machines

#29

The title contains hierarchical, which does not come back in the post. You probably need hierarchy, otherwise state charts become unweildingly large.

A statechart without hierarchy is just a state machine. It's the composition and hierarchy that turns a state machine into a statechart.

Re: Statecharts: hierarchical state machines

#30

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…

XState is an awesome library! Stoked to hear there's a new major version and visualizer coming. :)
Post reply on HN