10 ms·
The advice given in the article is to enumerate your states. Since usually when I'm designing an FSM I have an approximate idea of what's required, I find it ge
by andrewla 6y ago
The advice given in the article is to enumerate your states. Since usually when I'm designing an FSM I have an approximate idea of what's required, I find it generally much more instructive to dive right in.
Start with the "initial" state and start mapping out transitions -- at each node, list out all the transitions (exhaustively) from that node and assign them states. Walk through the happy path to the terminal state, then start fleshing out the various branches from there. Once you've got the graph, start merging states together as necessary, and since you've been making sure that your transitions are exhaustive at each step, it will be complete.
The next step is to step back and look at the entire machine for simplifications, but trying too hard to shoehorn two disparate states into the same state often leads to strange behavior (because transitions from one don't make sense in the other), so it's best to wait until you have some idea of the entire machine before you start combining states.