Cleanly representing and programming state machines is something I’ve tried a few approaches to in the past and I’ve never been fully satisfied with the results. Given that the world is increasingly driven by async programming models and complicated program control flows tend to produce less than beautiful code in an async callback or lambda¬† programming models this becomes a problem that is getting worse, not better.

One (the?) big problem is that control flow and composition across multiple async events/callbacks complete with proper error handling is messy. I’m not going to explain this as well as this video explaining Microsoft Rx, so just watch it:

So life gets better if you happen to be using .NET. As it turns out Microsoft brought all this to Javascript programming via Reactive Extensions for Javascript.

There are other folks doing the same things in JS, there is Flapjax

and Arrows or Arrowlets

I suspect some of the emerging Javascript MVC libraries and frameworks are accomplishing some of the same stuff in the interface between the model and controller, but I’m not sure yet, I need to look at them all again with this in mind. I would love to hear from anyone that can discuss some of the other JS frameworks or libraries in these terms!