3 ms·
I distinctly remember the first time I looked at a overly long and complicated model class and thought: "OMG, this is a state machine!" - a shortish refactor la
by jonasvp 9y ago
I distinctly remember the first time I looked at a overly long and complicated model class and thought: "OMG, this is a state machine!" - a shortish refactor later and it was much simpler to read and debug.
However, now I'm at a loss on how to teach the junior programmers at my company how to recognize which patterns scream "turn me into a state machine!" Several booleans triggering certain code paths in several methods is a pretty sure sign. Are there more?
- bsder 9y agoThe word "protocol" is a big red flag that you should be using a state machine. The words "event loop" probably mean you need a state machine. If "time" is an input variable, you probably have a state machine.
- yen223 9y agoIf you have a "status" field in your object, chances are you can represent it as a state machine