Live data from Hacker News

Why Developers Never Use State Machines (2011)

skorks.com

151–160 of 164 posts

Re: Why Developers Never Use State Machines (2011)

#151

A major problem with any state machine is that they tend to fall apart or become major bottlenecks if concurrency is required... It is still shared state, a thing to minimize. Usually message passing (current buzzword: reactive) approaches work much better.

> A major problem with any state machine is that they tend to fall apart or become major bottlenecks if concurrency is required...

One of the classic ways of architectural a concurrent system is as a collection of sequential processes implementing message processing loops as state machines.

If you mean that state machines can't deal with internal concurrency, that's not true either. Leaving out concerns about unmanaged state (mutable data not reflected in the state of the machine), a state machine provides a clear framework for managing concurrency:

(1) an unlimited number of events that produce self-transitions can be processed simultaneously;

(2) an event that would be processed the same in the start and end states of all currently running events and whose end state would not alter the processing of any currently running event can be processed concurrently,

(3) an event that would not be valid in the end state of any currently running event is invalid,

(4) any other event cannot be run concurrently, blocks new events entering processing, and must be evaluated for validity after each running event completes (it may become either runnable or invalid).

The last is a kind of bottleneck, but it's usually not introduced by the state machine so much as a feature of the domain.

Re: Why Developers Never Use State Machines (2011)

#152

Earlier quoted context omitted.

Definitely true for gamedev in my experience. I don't think I've worked in a game code base of nontrivial size without seeing some implementation of state machines.

The "some implementation" probably is part of the problem - if there was a good generic implementation included in the standard library so that it could and would be used in language tutorials (especially in languages where rolling nice state machine code is tricky), then developers would use them much more.

The problem with that is each system has slightly different requirements. Scripting state machines vs animation state machines are going to have very different constraints and end-goals.

[edit]

For example here is UE3's anim tree[1] editor vs Kismet[2].

[1] https://docs.unrealengine.com/udk/Three/AnimTreeEditorUserGu...

[2] https://docs.unrealengine.com/udk/Three/KismetUserGuide.html

Re: Why Developers Never Use State Machines (2011)

#153
post #85
post #78

Earlier quoted context omitted.

>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 I've not been ignoring them. I tried at least three different Haskell tutorials and articles explaining how cool it is. The problem was the author would show some code sand say 'see how easy it is to do this, and this, and this!', but I'd look at the code and have no idea wh…

I don't think 'three haskell tutorials' is ever enough to teach you a completely new programming language/paradigm. You wouldn't learn C in 'three C tutorials' either, would you? Perhaps a Haskell book with a project or two would be a better alternative?

I didn’t expect to ‘learn Haskell’, but learning anything at all about how the actual code being presented worked would have been nice.

Re: Why Developers Never Use State Machines (2011)

#154

State machine is useful when it is useful. I can see for certain string matching problem, internal management of certain data structure, it is going to be a handy improvement. However, specifically in web development, it is discouraged because the nature of the application itself. Think hard how states are managed in a typical service, the real states live in a DB. Which makes state machine less useful because the gr…

Would like to read more on this subject if anyone knows any resources.

Re: Why Developers Never Use State Machines (2011)

#155

Earlier quoted context omitted.

Well, after a few tutorials you should have noticed that it's a high-level language with clean syntax and a compiler that produces relatively fast binaries. That's a start. What else were you expecting?

Something that shows me how this is worth spending the time learning, when I could just as easily use another high-level language with clean syntax and a compiler that produces relatively fast binaries - but that are not functional - minus the learning curve.

Well shit. I guess teaching languages designed by academicians aren't for you. Same goes for blog posts written by random amateurs on the internet. A whole three tutorials, too! You should ask for a refund.

Re: Why Developers Never Use State Machines (2011)

#156
I use state machines all the damn time. Am I, then, no developer?

Maybe you meant to say that only competent developers use state machines. But that would place you outside their august company, leaving us little reason to credit your observation. In that world, the absence of state machines in one's code would reliably indicate incompetence.

But in fact, by definition, there is no computer program on God's green Earth that is not a state machine. Programming languages were created specifically to make the state machines they compile down to look more intuitive and less like, you know, state machines.

So the observation is really that our programs usually look the way they were intended to look, except when we abuse our language in pursuit of performance, elegance, or other consensual delusion.

Re: Why Developers Never Use State Machines (2011)

#157
post #148

Earlier quoted context omitted.

As much as I love haskell and want to say I've had those same experiences, that hasn't been my experience. Haskell forces me to write better code so often that it's painful when bad code will do just as fine. I'm always surprised how often bad code is the solution too.. And when I say the solution, I mean to all the points along the path that I may take to get to the final destination. And I'm not saying this because…

Well, despite what we tell ourselves, I think that most code we write is actually short lived. As in, it is only used for a short time. It might be in a zombie state for many years and even be revived, if it's an Open Source project, but that's not the common scenario. As a result, if most of the code written by most programmers is short lived and during that short life changes drastically, super-strict languages act…

well said thanks! probably what i might have said if i had more eloquent wording :D

Re: Why Developers Never Use State Machines (2011)

#159

"Why Developers Should Be Force-Fed State Machines" https://shopifyengineering.myshopify.com/blogs/engineering/1... I always thought all computer science students had to take a compilers course, or some course on theory of computation that required some level of competency in lexing/scanning/tokenizing and parsing. This blog post appears to be directed at "web application developers" who lack "awareness about state m…

The ECMAScript standard actually has a section on "Context- Free Grammars". In that section and subsequent sections there is discussion of tokens, terminals, nonterminals and productions. If a web application developer using Javascript read these sections of the language specification and became curious enough to do a little outside research on the terminology, then perhaps it is forseeable she might encounter the notion of a "state machine".

Re: Why Developers Never Use State Machines (2011)

#160
post #148

Earlier quoted context omitted.

As much as I love haskell and want to say I've had those same experiences, that hasn't been my experience. Haskell forces me to write better code so often that it's painful when bad code will do just as fine. I'm always surprised how often bad code is the solution too.. And when I say the solution, I mean to all the points along the path that I may take to get to the final destination. And I'm not saying this because…

Well, despite what we tell ourselves, I think that most code we write is actually short lived. As in, it is only used for a short time. It might be in a zombie state for many years and even be revived, if it's an Open Source project, but that's not the common scenario. As a result, if most of the code written by most programmers is short lived and during that short life changes drastically, super-strict languages act…

I agree with most of that, but I find that when my code is changing drastically is when I get the most help from my type checking, and find it most conspicuously absent when I use "less strict" languages.

I've no doubt this depends on context, on habits and approach, on skill with the languages in question, and on skill with effectively using static typing in general, so I'm not surprised that others' experiences differ.

Post reply on HN