Alan Skorkin writes a paen to the state machine. I've only written state machines for two classes of problems. They are indispensable for scanner-parsers, but I did not do the actual writing: a tool took my grammar and wrote the state machine for me. And for small logic problems I've written trivial state machines around the switch/case statement.
I think Skorkin (and van Bergen, whom he references) overlook the main reason few programmers write state machines: they are hard to reason about which makes them hard to write and hard to test.
1 comment:
Couldn't disagree more. If anything SMs are the easiest to reason and unit test since the possible number of possible outcomes is finite and can be enumerated in a unit test. Most likely generated from the same SM description file as produced the SM itself. Check out smg (state machine generator). Quite honestly I think that the only reason we don't use them more often is because they are so simple and easy that we just forget about them and automatically try for some overblown and complex solution.
Post a Comment