Live data from Hacker News

Why Developers Never Use State Machines

skorks.com

11–20 of 96 posts

Re: Why Developers Never Use State Machines

#11
State machines are a form of declarative logic as opposed to procedural, and declarative is often superior for modelling real-world activity.

Procedural logic tends to be brittle - small changes have unintended consequences. Declarative models tend to be more robust and, especially with domain-specific languages, safer for domain experts to manipulate. You can certainly design domain-specific languages for the subset of declarative systems that are state machines.

I've happily used state machines in enterprise projects. One was tracking rates of financial instruments, where they would be in various states of validity (i.e. is it a live offer?). Another was a logistics app, where data would move through various states of being cleansed and approved, or rejected. We built a UI around it. By isolating the state definitions and their transitions, it was easy to validate the program's model with business exprts.

Re: Why Developers Never Use State Machines

#12
Simple, because most developers are not computer scientists i.e. no formal training in finite automata, computability, complexity, nondeterminism, regular expressions, non regular languages, context free grammars and languages, Turing machines, halting problem and underlying math in general.

If they did, trust me they would use state machines without too much reservation where appropriate. But as it is, the concept is foreign to most and good ones intuit their way into implementing one perhaps (just guessing here).

Re: Why Developers Never Use State Machines

#16
I (as a Java developer) use state machines often - and know other developers who do same too. I use mostly enums (though there are other ways of achieving it), as explained in this post:

Java Secret: Using an enum to build a State machine: http://vanillajava.blogspot.com/2011/06/java-secret-using-en...

Re: Why Developers Never Use State Machines

#17

Use them all the time, have for all my career. They organize complex code, dissect complex set-flag-here-and-test-there spaghetti into a matrix of states and events that can be exhaustively examined and debugged. Yes you have to organize your code to feed the machine (Vol is hungry! We must feed Vol!) But you have to organize your code somehow, and feeding a state machine can actually be easier to understand that fla…

True, it's better to have a set of states instead of a dozen boolean values. It gives better code, and better organized databases too.

Re: Why Developers Never Use State Machines

#18
I've always used a state machine whenever I've parsed XML using an event based parser (SAX).

Although lately I've been replacing an explicit state variable with a stack containing the current element path, since that's pretty easy to do using modern languages.

Re: Why Developers Never Use State Machines

#20

Simple, because most developers are not computer scientists i.e. no formal training in finite automata, computability, complexity, nondeterminism, regular expressions, non regular languages, context free grammars and languages, Turing machines, halting problem and underlying math in general. If they did, trust me they would use state machines without too much reservation where appropriate. But as it is, the concept i…

It'd be interesting to poll programmers who have computer science degrees, electrical engineering degrees, and are self taught to understand the percentage of each who understands state machines, even just at a basic level.

I'll wager electrical engineers understand state machines more often than the other two categories. Stage machines are rather useful in designing hardware.

Post reply on HN