Live data from Hacker News

Why Developers Never Use State Machines

skorks.com

91–96 of 96 posts

Re: Why Developers Never Use State Machines

#91
post #57

State machines are useful because they're 1) computationally fast 2) simple to implement 3) easy to read [up to a certain size] The big problem with state machines relates to the number 3 and regards the general concept of "state". Managing state is the challenge of computation! As you add states and transitions, the complexity increases dramatically, exponentially in some cases. This is why novice programmers strugg…

Good points. Sometimes it's nice to be able to visualize an explicit directed graph of states (vertices) and events (edges), though. It helps identify inescapable states and unhandled events.

Re: Why Developers Never Use State Machines

#92

Earlier quoted context omitted.

I had the same reaction. Almost nothing but FSMs in game AI. Makes me wonder if we need to look beyond FSMs for the next level of intelligence.

The natural next step is a PDA. Perhaps you could use this type of system to model an AI that can get distracted or become faced with an intermediate task and then return later to the original objective?

I've used PDA in games A.I. programming several times too. In fact I'd be surprised to see anything beyond a casual game that didn't use high level 'task stacks'.

Re: Why Developers Never Use State Machines

#94
post #89
post #23

Having used state machines a lot for embedded development, I find that they have one huge drawback: the resulting C code is unreadable, which turns maintenance into a nightmare. SM have a key quality: they are a compact and unambiguous way for specifying a behavior. If your system's behavior is set in stone, it's worth specifying it as a SM and implementing it as one. This SM is also great to include in a spec, stand…

the resulting C code is unreadable, which turns maintenance into a nightmare. I've been doing embedded development for a few years and I love our state machines, they're a pleasure to work with. Maybe yours just sucked.

I feel the same .. all my state machines are lovely. There is nothing quite so rewarding as making an:

    enum { 
        APP_START,
        APP_INIT,
        APP_DO_TASK_A,
        APP_DO ..
        APP_FREE,
        APP_QUIT
    }
.. the center of your applications world! ;)

Re: Why Developers Never Use State Machines

#95
post #44

Can anyone recommend a good introduction to using state machines in code? Especially something in javascript/python? I know what an SM is and how it works, I just want to know how to use an SM library to actually do all these cool things.

A lot of the IBM Developer articles are apparently crap, but I found this one interesting and well done, some years ago. The article date looks different, now, and IBM has redesigned the site since I originally read it, but I think -- at a glance -- that it's the same article. http://www.ibm.com/developerworks/library/wa-finitemach1/ http://www.ibm.com/developerworks/web/library/wa-finitemach2... http://www.ibm.com/d…

I have to think that somewhere around 2007 IBM started offering massive bonuses for writing site content and HOWTOs.

Re: Why Developers Never Use State Machines

#96
post #95

Earlier quoted context omitted.

A lot of the IBM Developer articles are apparently crap, but I found this one interesting and well done, some years ago. The article date looks different, now, and IBM has redesigned the site since I originally read it, but I think -- at a glance -- that it's the same article. http://www.ibm.com/developerworks/library/wa-finitemach1/ http://www.ibm.com/developerworks/web/library/wa-finitemach2... http://www.ibm.com/d…

I have to think that somewhere around 2007 IBM started offering massive bonuses for writing site content and HOWTOs.

Your reply motivated me to look, and my vague recollection is correct: I exchanged a couple of brief emails with the author back in 2007, when the articles did indeed first come out.

However IBM did it, they were entered into some sort of site publishing schedule such that he'd lost track of just when they were coming out.

Seemed a nice enough fellow. From the articles and his bio, I imagine (perhaps incorrectly) his motivation was more pedagogical than remunerative.

Post reply on HN