Introduction to Hierarchical State Machines
barrgroup.com
barrgroup.com
Take for example React with a router. When you are in a given view, that component is your active state. Nested views are nested states of that component. Entry and exit actions are executed within the lifecycle hooks (componentWillMount, componentWillUnmount).
We take these concepts for granted because we're used to working with them, but if you tried to make a multi-view/nested-view single page application using only, for example, jQuery...you would find that there was a reasonable amount of complexity arising from state teardown and mounting. And if you found the exercise to be trivial, then I would be willing to bet that your resulting structure could be classified as something akin to a Hierarchical State Machine :)
If you've ever designed something that should respond to requests/activity, you probably understand the challenge of representing and understanding the multiple concurrent states your software system inhabits. HSMs (aka statecharts or Harel statecharts) are a great way to model this problem domain.
which led me to David Khourshid's worthwhile "Infinitely Better UIs with Finite Automata" presentation, https://www.youtube.com/watch?v=VU1NKX6Qkxc
and the article "You are managing state? Think twice", http://krasimirtsonev.com/blog/article/managing-state-in-jav...
https://aleph2c.github.io/py-activeobject/index.html
It's not done yet, but seeing this post on the front page of hacker news was too tempting for me not to share.
One key issue in the tooling however (which is perhaps applicable to all "visual" programming languages) is the inability to view proper 'diffs' of changes. This was eased in Statemate somewhat because all statecharts were stored as plain text files but I feel it could use some good ideas.
I wonder how they're managing this problem in HSM's. Seems like transitions between parent/child states would need some kind of protocol to define state entry/termination criteria so that the concrete dispatch mechanisms themselves could be abstracted away from the parents/children.
Maybe its just me.
It might just be this codebase, but I do not see the appeal to HSM's. I'll stick with my standard flow control (while, for, break, return) and compose functions from other functions. It sure is nice to make calls that actually return.