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: http://ecn.channel9.msdn.com/o9/ch9/4d56/91d0ae4f-e2fb-44b7-8a38-9e25011e4d56/dc2010keynote_ch9.mp4

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.

http://channel9.msdn.com/Blogs/Charles/Introducing-RxJS-Reactive-Extensions-for-JavaScript

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

http://www.flapjax-lang.org/

and Arrows or Arrowlets

http://www.cs.umd.edu/projects/PL/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!