8 ms·
Can you clarify why state machines are easier to debug?
by eliben 12y ago
Can you clarify why state machines are easier to debug?
- hadoukenio 12y agoI've worked on large state machines in the past, which were rock solid and easy to work with. As the code was built using state transition tables, state machines were automatic. I would hate to think of how to juggle these systems using co-routines.
- eliben 12y agoI'm not sure you're answering my question, though. You made a claim that state machines are easy to debug and coroutines are not. What makes you think they are not? I'm really just curious. FWIW I've done significanly more work with state machines in the past, and I find them reasonable to debug, though not as easy as straight line code because in the latter the full state history (execution stack) is always known, while in state machines you usually need to do extra work to trace how the machine got to some state.
- hadoukenio 12y agoSorry I forgot my why. Probably because by using state transition tables the system's whereabouts is afforded salience. Compare this to a co-routines being sprinkled throughout a large code base, essentially creating asynchronous goto-hell.
- deleted 12y ago[deleted]
- xsmasher 12y agoWhen I'm writing a state machine I make sure to add a method like machine.changeState( newState, "reason"); Now you can add a dlog inside changeState to see a history of state transitions and why they were made; useful for figuring out why you got where. That's not something inherent to state machines, though.
- lmm 12y agoAn explicit state machine makes it very easy to observe a) what the current state is b) what the possible states are.