Ragel State Charts
In my experience SMC ("state machine compiler", tres original no?) is better-suited than ragel for working with state machines that're easily specified as "state charts".
The difference is that ragel is oriented around consuming a stream-of-chars: the generated state machine expects to be consuming chars as input.
You can pick up on this in the writeup even though Zed's not pointing it out: he first has to define his messages as chars (eg: 'done' == 'D'), then he specifies his states + transitions in terms of those definitions.
SMC instead generates methods for each 'message' and it's the enveloping program's responsibility to call the correct method to update the state.
This is cleaner for simpler state machines.
None of this is intended as a knock on ragel, btw: it's a very solid piece of software, and for more-complicated state machines should be the go-to choice.
In the article, Zed says, "it’s just that nobody learns about state machines unless they take an obscure compiler design class. Very few universities teach state machines as a method of specifying the logic for a program."
My background is as a EE, and I work in hardware. I can't imagine not knowing about state machine design. Is Zed's statement accurate for those with a pure software focus?
Zed seems to have a freaky ability not only to implement high quality code himself, but to find high quality code written by others, absorb it, and then explain it. Strikes me as the qualities that make a successful angel investor.
All of this sounds super fancy, but it’s really based on solid research done on state machines over the years. Adrian simply took all the best research and built a sweet little domain language for state machines.
This is why research and open source are important. And kudos to Adrian.
Erlang encourages this style through its OTP library; all of the default OTP behaviors include state machines as part of their operations, or make it so easy that they might as well. (gen_fsm is, as the name implies, a finite-state-machine, and it's trivial to use pattern matching to use a piece of the state in gen_event or gen_server to do the same thing). It doesn't sound like it has the full range of awesome that Ragel state charts do, but it has a lot of the value. It definitely gives you a lot of confidence that nobody can trick your server into doing something unexpected with weird input unless you do something very wrong yourself.
I'll just state here that this is also what powers _why's excellent Hpricot HTML parser.
Back in my last job, I implemented a Java libconfig clone using Ragel. It was the most fun I ever had at that company.
this is an awesome article... nice job, Zed. I want to try it.