Jeff Mesnil
Weblog · Dev · Photos · Books

stomp-websocket converted to CoffeeScript

November 3, 2011

One of the joy of working with Open Source projects is when you get an awesome contribution coming out of nowhere.

Jeff Lindsay requested to pull one of his branch of stomp-websocket where he converted all the code to CoffeeScript, added unit tests with a mock implementation of a WebSocket server. This work is a preliminary for more features (including a much-needed support for STOMP 1.1).

When he offered to pull its branch, he wonders if the move to CoffeeScript was controversial and if I would accept it.

stomp-websocket is meant to run inside Web browsers and leverage the Web Sockets API. When I wrote it, JavaScript was a no-brainer.

However I have started to question this choice recently.

I have a pet project where I use node.js and I am making countless JavaScript code mistakes (I was bitten by this one last week, thankfully I have not released my project yet).

As much as I like JavaScript and its related HTML5 APIs, I must admint I am not a good JavaScript programmer and I want a language that helps me instead of trapping me. I started to read about CoffeeScript as a replacement of JavaScript. I find the language more pleasing to read even though some syntax conventions makes it more cryptic than concise.

I am quite pleased with the new code of stomp-websocket in stomp.coffee. It reads much better than the original stomp.js, there are no longer noisy this, that or vars (when they are not missing by errors!).

However, the JavaScript code compiled by CoffeeScript does not look good. I suppose I must stop to look at the compiled JavaScript and instead consider it as the assembly language of the Web.

In any case, the transition should be transparent for developers using stomp.js: the new generated stomp.js offers the same API than the previous one.

If that is not the case, please report any regression or bug on GitHub issue tracker.

As usual, do not hesitate to contribute:

git clone git://github.com/jmesnil/stomp-websocket.git

As Jeff Lindsay can attest, I welcome good contributions :)