20 ms·
I think using a state machine can make the resulting code more elegant in some cases by coupling state changes and effects. But that’s not why they are useful.
by cacozen 5y ago
I think using a state machine can make the resulting code more elegant in some cases by coupling state changes and effects.
But that’s not why they are useful. In my experience, they have been useful because they help map (even mentally) all individual possible states a piece of code can be in, and how the code should behave in each case. In the process, I usually discover and deal with more edge cases, more combination of states and behavior, and as a consequence the code is bigger/fatter. But also more robust.
- RobertKerans 5y agoThis is important, and it's probably the main reason I like using them so much. But then surely the comeback is that what I'm then attempting to do is produce a diagram in code, when I could just write the diagram on paper, check it, then write some (possibly simpler) code. Not in all cases, naturally, but often?
- runawaybottle 5y agoYeah, I think you articulated that better than a lot of us here. That, in a sense, your diagram becomes your psuedo-code, or even further, your actual implementation. My initial defensive impulse to this topic was mostly to take a stand against frontend code that is becoming increasingly obtuse over the years.