Apr 01

CoffeeScript, Whitespace, and Coffee

JavaScript, Tech 2 Comments »

I enjoy learning new languages. I am not on the yearly diet as the Pragmatic folks would desire, but when I can…. I enjoy expanding my mind as I have definitely experienced the fact that learning a new language makes me program differently in all of my other languages.

Clojure and Scala are interesting to me in the land of Java, but that isn’t where I have been spending time (until recently). I have been very much enjoying Jeremy Ashkenas’s CoffeeScript. What’s not to like? Jeremy has managed to create a language that cleans up many of the issues in JavaScript, and codifies much of the Good Parts into source form. Ruby is my favorite language, and this gets really close to my ideal mental model.

When talking to Brendan Eich about the language, he very much appreciates it, and also the fact that it maps nicely to the JavaScript model (versus something like GWT and Java mapping on top of JavaScript say).

In some ways it feels bizarre to write in a high level language which gets converted to another high level language. One thing that has been enjoyable though is learning this language. The killer features for me are:

  • Jeremy takes care of things like documentation. The main site is the best introduction and documentation for any language.
  • Source code as byte code. I don’t enjoy reading byte code. I do enjoy reading JavaScript code (a language I know well) though. It is fantastic to be able to play with a new language and instantly be able to see the JavaScript output, whether it be small things via the inline site, or via -w / cake watch.

Try CoffeeScript

One feature that I am not a huge fan of is the pythonic importance on significant whitespace. Notice the image above, and how the ordering of elements made a difference to the output.

It is very cool that Firefox is going to “natively” support loading up CoffeeScript, and I think that someone needs to create Coffee and do to Java what CoffeeScript has done to JavaScript.

You could argue that this has already been done….. Groovy? Oh and thanks to the great work of Charles, Tom, Ola, and friends…. I can even use JRuby over there…..