3 ms·
If you try to implement an actual state machine (or even interlinked ones like TCP) in this style you will have a very bad time. The FSM model is restrictive b
by theptip 2y ago
If you try to implement an actual state machine (or even interlinked ones like TCP) in this style you will have a very bad time.
The FSM model is restrictive but this makes it much easier to exhaustively cover and validate all state combinations.
To be concrete, the kind of code you end up writing in your non-FSM approach (for a non-trivial example where you have, say, an RPC per state transition or other logic between the transitions) is
def finish():
if state == WAIT:
#error
elif state == FILL:
…
And worse, you need to validate your state in each transition, which ends up being duplicative and error-prone vs. just specifying your transitions once and then depending on them to enforce that the states are valid.
FSMs are a great pattern when they apply cleanly.