Live data from Hacker News

Why Developers Never Use State Machines (2011)

skorks.com

11–20 of 164 posts

Re: Why Developers Never Use State Machines (2011)

#11
post #9
post #5

If you've ever do any game programming you'll be drowning in state machines.

network protocol as well, hell, any non-toy network application ends up containing a state machine either implicitly or explicitly

Gesture detection/interaction here. All state machines all the time.

Re: Why Developers Never Use State Machines (2011)

#12
Traditional programming languages and imperative thinking don't lend themselves to writing state machines, so its not really that surprising that they're under utilized.

Its kind of frustrating constantly reading posts where people shit on functional programm(ers|ing) for being too ivory tower-y or whatever, when its kind of hard not to be when a lot of the older FP guys have spent the last like 20-30 years going "yo this is dope you guys should really be doing this" and getting largely ignored. State machines are super commonly used in languages where you can (easily) construct ADTs and pattern match on them.

Re: Why Developers Never Use State Machines (2011)

#13
You could even go as far as saying that a class in some forms is a state machine. Networking is a huge application of state machines. Microcontrollers usually have a small state and step through a switch statement in an infinite loop. OpenGL is a state machine. If you write a state machine, it's easier to implement it "perfectly" than other methods, and other parts of your program are able to interact with it in more straightforward ways.

Re: Why Developers Never Use State Machines (2011)

#15
post #12

Traditional programming languages and imperative thinking don't lend themselves to writing state machines, so its not really that surprising that they're under utilized. Its kind of frustrating constantly reading posts where people shit on functional programm(ers|ing) for being too ivory tower-y or whatever, when its kind of hard not to be when a lot of the older FP guys have spent the last like 20-30 years going "yo…

Plenty of imperative domain spaces use state machines, gamedev and the like come to mind in particular.

Re: Why Developers Never Use State Machines (2011)

#16
post #9

Earlier quoted context omitted.

network protocol as well, hell, any non-toy network application ends up containing a state machine either implicitly or explicitly

Gesture detection/interaction here. All state machines all the time.

Life cycle management, process synchronization, lockfree data structure, user-space networking... I can't remember the last time I didn't use a state machine.

Re: Why Developers Never Use State Machines (2011)

#17
State machines are essential for a lot of programming tasks -- I wish they were more explicit more often, because there always is an implicit state machine lurking in there somewhere, and code would be cleaner with the state machine made explicit.

For example ...

I was brought on to work at a startup a few years ago by an old-time acquaintance that was CEO of a startup ... the company's proposed product sounded interesting, and I believed in her skills and background and had decent rapport with her. I was wary of the VP Engineering and a few others, but it was to be my first post-move-out-of-SF-Bay-Area remote startup job and I thought I could make it work.

I show up in Santa Clara, CA to make sure I really want to do this ... and after joining we spend the next few days going over architecture, implementation-so-far, etc. Part of the product's job is to discover and categorize servers and networking devices, the basic software deployed on them, etc. Apparently this aspect has been in design/implementation for several months, but it's not working very well, and the problem and approach aren't articulated very well. I have a chance to look at the code a bit.

I eat lunch with the CEO and she asks me how I'd approach the problem, and I advocate breaking everything down into state machines with well-defined transitions ... both for interacting with the environment, and for storing info in the back end -- there's ample opportunity for things to go wrong, to require retries, etc., and tracking these interactions with state machines makes it much easier to efficiently and quickly deal with the environment and back end in asynchronous fashion, and to separate different levels of discovery (network / IP; finding credentials that work; OS determination; software inventory; storage inventory; etc.) much easier.

In the next day's architecture discussion I then hear the VP Engineering use a few of my words and draw a few poorly formulated diagrams that don't do the task much justice ... it's apparent the CEO has discussed the problem with him and urged a new look. I had to start work on my piece so I didn't follow their developments much, but I heard later they actually purchased and licensed for significant money a "finite state machine package" of some kind. All they needed were ENUMs, (preferably async-result) functions to try something out, and then transitions between enums based on the results. That discovery code was always buggy, never did work right.

That was one of many fiascos. There were so many other fiascos, and they all cost me lots of sleep, some of my sanity, and some self-respect. I lasted almost three years there (some early players were pushed out but the product never really got better). I would have been happier quitting the first week, or better yet never joining.

Re: Why Developers Never Use State Machines (2011)

#19
post #12

Traditional programming languages and imperative thinking don't lend themselves to writing state machines, so its not really that surprising that they're under utilized. Its kind of frustrating constantly reading posts where people shit on functional programm(ers|ing) for being too ivory tower-y or whatever, when its kind of hard not to be when a lot of the older FP guys have spent the last like 20-30 years going "yo…

> State machines are super commonly used in languages where you can (easily) construct ADTs and pattern match on them.

I had the opportunity to use F# for the first time last month, and I experienced this first hand -- it was far easier to write a procedure as a sum type with transition functions than it would have been to write it procedurally. And with all the advantages of having the states of the system and their transitions laid out explicitly, why fight it?

Re: Why Developers Never Use State Machines (2011)

#20
post #12

Traditional programming languages and imperative thinking don't lend themselves to writing state machines, so its not really that surprising that they're under utilized. Its kind of frustrating constantly reading posts where people shit on functional programm(ers|ing) for being too ivory tower-y or whatever, when its kind of hard not to be when a lot of the older FP guys have spent the last like 20-30 years going "yo…

What? No, that isn’t true at all. State machines come before the FP/IP divide even existed.

State machines are also intrinsically stateful, that should be obvious.

Post reply on HN