Barr Group, an embedded systems consultancy, publishes articles on state machines, embedded C, coding standards and firmware design.
HN commenters cite it for embedded C coding standards and state machine material, including Michael Barr's work. One links a post on AI agents finishing a novel.
> I'm mostly concerned about visualization
Almost all of the finite state machines use the same underlying graphing tool, "GraphViz," to do their rendering. It sounds like you might want that.
There is an emscripten transcompile for the web called viz.js.
.
> if you have actions/guards that don't appear on the visualization
Actions do appear on the visualization. I'm still not sure what you mean by guards.
.
> imilarly, by recursion I meant putting states inside states (from a behavior perspective you would call them compound states); Both PlantUML and XState supports that. Parallel states [1] are compound states with multiple distinct regions
It looks like one of XState or PlantUML tried to rename Heirarchical Orthogonal State Regions, and the other copied the first one.
.
What you're calling "recursion" is called a Heirarchical State Machine. It appears that XState uses the regular name for these:
https://xstate.js.org/docs/guides/hierarchical.html
External reference:
https://barrgroup.com/embedded-systems/how-to/introduction-hierarchical-state-machines
.
What you're calling Parallel States is properly called an Orthogonal Region. It's problematic to call these parallel for exactly the following statement, where you suggest that this "doesn't necessarily imply threading;" this wrong name that XState and PlantUML has used has confused you.
*All state machines are by definition single threaded single context. This may not and will never be implemented…
To these links I would also add Miro Samek's book "Practical UML Statecharts in C/C++," which covers details of implementing (hierarchical) statecharts. The book includes a chapter that analyses different ways of encoding extended state machines (Miro concludes a function pointer, with one event handler function per state is the best for C/C++. I don't think this is the encoding that the linked Rust article uses). A simple algorithm for implementing HSMs is described. A large portion of the book is devoted to what you might call "UML Statecharts -- The Good Parts," the parts of the UML statecharts spec that are easy to implement in a real-time setting, and idioms/patterns to achieve similar results as the parts of the spec that are not easy to implement.
Some of Miro's online writings:
https://barrgroup.com/embedded-systems/how-to/state-machines-event-driven-systems
https://barrgroup.com/embedded-systems/how-to/introduction-hierarchical-state-machines
https://www.drdobbs.com/who-moved-my-state/184401643
[Edit: clarity]
Might I suggest better alternatives as more pleasant alternatives to the stuffy MISRA C book:
- "Embedded C Coding Standard" by Michael Barr[1], CTO and co-founder of Barr Group, the guy who inspected the ECU code and testified in Toyota's unintended acceleration lawsuit. Good stuff.
- "Embedded System development Coding Reference guide" written by the Software Reliability Enhancement Center of Japan [2], which covers and expands on MISRA C and more. It's a joy in examples, explanations and eye-pleasing aesthetic. I love it.
[1] https://barrgroup.com/sites/default/files/barr_c_coding_standard_2018.pdf
[2] https://www.ipa.go.jp/publish/qv6pgp00000011mh-att/000065271.pdf
Thanks for the reply. My comment was in reference to the Visual Basic Calculator program described here: (perhaps "VBScript" was not accurate)
https://barrgroup.com/Embedded-Systems/How-To/State-Machines-Event-Driven-Systems
That VB calculator is shown as an example of "The Problem" with event driven programming, but I just see it as an example of why poorly designed programs are hard to reason about and buggy.
I did not see the coffeescript / Python calculator.
That was done via Airworthiness Directive (a mandatory prod patch for aviation), not by original engineering design intent. Similar story with the Patriot missile defense battery.
* - https://www.federalregister.gov/documents/2020/03/23/2020-06092/airworthiness-directives-the-boeing-company-airplanes
* - https://barrgroup.com/sites/default/files/case-study-patriot-missile-defects.pdf
You're correct. (https://barrgroup.com/Embedded-Systems/How-To/C-Volatile-Keyword)
But again, you're telling the compiler that you know what you're doing, and to not perform its normal optimization. I'm not well-versed in compiler design, but I think that's the tradeoff you have to make between trusting the user's design choices, or not.