How to define parallel states?


#21

That’s a great question @mrthomaswhitehead—and something that we wrestled with in developing the parallel states feature.

One perspective is that “transitions should be defined in the states in which their events are possible.” If that’s the case, then you’d probably want to specify transitions to multiple states, as per your example:

Example& 
  Menu
    Menu Shown
    Menu Hidden
  Section
    Section A
      click menu button -> Menu Hidden, Section B
    Section B
      click menu button -> Menu Hidden, Section A

To us, this felt a little weird on the “to” side of the transition, since we’re trying to convey the configuration of both parallel children. This transition might make more sense on the parallel parent (Example&), but then we lose that information about when the text input event can occur.

The other philosophical approach would be to think of events as completely exogenous—and only focus on how the events affect the states:

Example& 
  Menu
    Menu Shown
      click menu button -> Menu Hidden
    Menu Hidden
      click menu button -> Menu Shown
  Section
    Section A
      click menu button -> Section B
    Section B
      click menu button -> Section A

This feels rather repetitive, rather than having a single event cause all the necessary actions to occur.

We ultimately decided on the latter to get the feature shipped, but both sides probably have arguments for them. We’re definitely open to thoughts on which approach is best or alternatives.


#22

This is interesting. The more I tried to think of examples of when this feature would be used, the more I found myself describing abstractions of other processes
Shut the door -> Door_Shut, Light_Off
…that could benefit from a pseudo-event describing the causality between the two new states, or attempting to use states to describe and hold variables
Light Fire -> Room_Hot, Room_Light

Does this speak to the value of statecharts being limited to describing smaller components individually, rather than mapping out more complicated systems in single statecharts?


#23

Harel statecharts are capable of modeling complicated systems (he designed them for fighter jets!).

There are a few features that can be helpful which aren’t in Sketch.systems. @kevin mentioned earlier in the thread that he wasn’t sure how useful parallel states would be without transition guards and extended state variables. The FAQ on the homepage covers a bit on why we haven’t added those.


#24

I’m trying out the feature as it is currently released and I think the way you proposed and implemented it makes total sense for my original use case (https://sketch.systems/phivk/sketch/18365a439a81fad25c2dbe9fbd26a091)

Thanks and congrats on the release :raised_hands: