statecharts / statecharts.github.io

There is no state but what we make. Feel free to pitch in.
https://statecharts.dev/
312 stars 53 forks source link

Why is the substate of E required in the On-Off Statechart example? #6

Closed LNNowak closed 6 years ago

LNNowak commented 6 years ago

Hi, I have a simple logical question I can't myself find an answer to. Why do we need a substate of E in the On-Off Statechart example? Why do E and F can't look exactly the same as A and B? So that when we enter D we automatically enter E and ignore the flick event for 0.5 s. Thanks.

mogsie commented 6 years ago

Hi! and thanks for the question!

The behaviour of A and B is different than that of E and F:

When in A, and the "flick" event happens, it actually resets the timeout. This is because "flick" causes A to exit and enter again, thus resetting the timeouts.

When in E, however, the "flick" event is handled by a substate. The E state doesn't exit and enter again, since it's the G state that does that, with no side effects.

I could use an internal event in E, but in order to do that I'd have to first explain internal events, so I opted to not do that.

I should probably try to explain the difference in the behaviour on the page, I'll try to get to that soon!

LNNowak commented 6 years ago

I understand now. It wasn't clear at first, I misread this part:

only if it has been in A, uninterrupted, for 2 seconds

I think it might be helpful to include your comment on resetting on the statechart's web page. It explains it more naturally, at least to me.

mogsie commented 6 years ago

I'm glad to help, and thanks for helping out with pointing out something unclear. I added a few sentences in bd220ff — Do you think it helps the explanation?

LNNowak commented 6 years ago

I consider it more comprehensible now. I found one mistake though:

It is only when the "flick" event hasn't happened for 2 seconds, that the next "flick" will turn it off.

I believe it should be written turn it on.

I'd also change this:

the light will actually turn off.

To this: the light will eventually turn off.

mogsie commented 6 years ago

Thanks again, and well spotted!