Workiva / state_machine

Easily create a finite state machine and define legal state transitions. Listen to state entrances, departures, and transitions.
Other
61 stars 24 forks source link

CP-2203 IllegalStateTransitions shouldn't exist #24

Open mahonnaise opened 9 years ago

mahonnaise commented 9 years ago

If you have to guard against doing illegal transitions, you'll need another finite-state machine implementation (e.g. a switch) to do this. The current FSM implementation creates the very problem FSMs are meant to solve.

Doing the transitions directly is also, let's say, unorthodox.

Usually, you just throw events at the FSM and it transitions in response if it feels like it. E.g. in a platform game, if the player's character is already in the jumping state, pressing the jump button once more won't do anything (unless there is a doubleJumping state the FSM could transition to).

https://en.wikipedia.org/wiki/Finite-state_machine

[An FSM is] an abstract machine that can be in one of a finite number of states. The machine is in only one state at a time; the state it is in at any given time is called the current state. It can change from one state to another when initiated by a triggering event or condition; this is called a transition. A particular FSM is defined by a list of its states, and the triggering condition for each transition.

Also check what Robert Nystrom (the author of pub and dartfmt) wrote about this topic in his spare time:

http://gameprogrammingpatterns.com/state.html

evanweible-wf commented 9 years ago

@mahonnaise thanks for the feedback! I read through the post that you linked at it was a good read. I'll admit that I had a bit of tunnel vision when designing this - it fits our use case well, but I agree that it isn't a true FSM. While it won't be right away, I'd definitely like to address this. If you don't mind, could I tag you when there's a PR ready?

zeppelin commented 1 year ago

@evanweible-wf @mahonnaise I'm not developing with Dart anymore. Wanna take over this PR?