4 ms·
When I first saw Statecharts I failed to realize that Statecharts are _NOT_ state machines, state machines are the building block. Quote from the paper: "...
by emmanueloga_ 6y ago
When I first saw Statecharts I failed to realize that Statecharts are _NOT_ state machines, state machines are the building block.
Quote from the paper:
"... a complex system cannot be beneficially described in this naive fashion [state machines], because of the unmanageable, exponentially growing
multitude of states, all of which have to be arranged in a ‘flat’ unstratified fashion, resulting in an unstructured, unrealistic, and chaotic state diagram. To be useful, a state/event approach must be modular, hierarchical and well-structured. It must also solve the exponential blow-up problem by somehow relaxing the requirement that all combinations of states have to be represented explicitly."
So regular state machines are usable up to only a few states and transitions. Implementing the whole set of Statecharts features is far from the quick exercise of building an ad-hoc, implicit state machine. Fully using Statecharts introduces some overhead. But the true power of Statecharts shows when using hierarchy, parallel states, history and so on, things that build on top of state machines and take a bit more investment to learn how to use.
--
Another interesting aspect is the "formal semantics". Quote:
"The statechart formalism turns out to be quite a challenge when it comes to providing formal semantics ... The main difficulty is not in the depth of states or the orthogonality constructs themselves; ... The more difficult problems arise with the introduction of events and conditions that are generated within the statechart itself, and are sensed in orthogonal components."
So the idea is that given the same Statechart diagrams, two different implementations should end up in the same states when subjected with the very same sequence of events.
Perhaps this is less of a problem to build GUIs and other applications that don't have super stringent requirements on safety and verifiability.
- jbeard4 6y agoRegarding the "formal semantics", you are correct that different implementations of Statecharts have had different formal semantics, however some effort has been put toward standardization, the main one probably being the W3C SCXML standard, which specifies a pseudocode algorithm for execution of Statecharts: https://www.w3.org/TR/scxml/#AlgorithmforSCXMLInterpretation https://www.w3.org/TR/scxml/#AlgorithmforSCXMLInterpretation It also provides a test suite that implementations can use to check compliance: https://www.w3.org/Voice/2013/scxml-irp/ https://www.w3.org/Voice/2013/scxml-irp/ There are a number of conforming implementations in various programming languages.
- kazinator 6y agoStatecharts are in fact descriptions of state machines. They are just not ordinary state machine diagrams based on a single, scalar state variable. The state expressed in Statechart could be turned into a single variable, and the chart could be refactored into a flat state transition diagram. But that diagram would potentially be huge compared to the state chart description. The state chart condenses that description by avoiding the duplication of some sub-state-machine for every change of some variable which is irrelevant to it. E.g. suppose a device has two master modes of operation, A and B, in which it responds to inputs in totally different ways. Suppose that mode A and B retain their internal state when the mode switch takes place. If we don't use a hierarchical state chart, we end up having to represent what happens when a certain input arrives in a state under mode B, for every possible state in mode A which is not actually in effect and irrelevant. Basically, we have to deal with the product state space, in which the explosion leads to numerous identical combinations.
- emmanueloga_ 6y agoState machines as formally defined are incredibly low level, lacking even things like guards (predicated transitioning) and transition actions. So Statecharts adds a lot on top of them, but yeah, the foundation is FSMs.