3 ms·
Array of callbacks (or long switch which is essentially the same) is a standard method to implement state machine.
by vbezhenar 8y ago
Array of callbacks (or long switch which is essentially the same) is a standard method to implement state machine.
- kaoD 8y agoAnd that's why you should use a thoroughly tested implementation instead of implementing a bug-ridden ad-hoc square wheel. "Whoopsies, I forgot to ban some state transitions" won't happen if all you're writing is a state machine spec, and not a state machine spec and its ad-hoc implementation. Don't roll your own crypto? Extend it to "don't roll your own low-level constructs".
- ernst_klim 8y agoYou can use type system to ensure that there are no wrong state transitions, e.g. you could transit to another state only if you are authorized.