Recently I’ve played with node.js and the Play! framework and I came across CoffeeScript.
CoffeeScript is a language which compiles to JavaScript. The advantage over using JavaScript is basically having a more compact language which looks a lot like Ruby. Sometimes one very readable line of CoffeeScript translates into 7-10 complex lines of JavaScript.
My dear friend Alec recommended Sublime Text, a relatively new lightweight editor similar to TextMate. Starting to learn CoffeeScript I decided to give Sublime a shot and I liked it a lot. Now I also use Sublime to do the Java coding for Play! framework code. Usually you want a richer IDE like Eclipse or IntelliJ for Java but since Play! compiles the code on the fly and comes with perfect compile errors in the browser, a lightweight editor like Sublime works just fine.
Here a little tutorial how to setup Sublime to start coding CoffeeScript:
- Install CoffeeScript (You need to have node.js and the node package manager installed):
npm install -g coffee-script
- Download and install Sublime Text Editor
- Save the CoffeeScript.tmLanguage here: ~/Library/Application Support/Sublime Text 2/Packages/CoffeeScript/
- Create the CoffeeScript.sublime-build here: ~/Library/Application Support/Sublime Text 2/Packages/Users with the following content:
{"cmd": ["coffee", "$file"], "selector" : "source.coffee", "path" : "/usr/bin"}
- Now open Sublime and create a helloWorld.coffee:
console.log "Hello world"
- CMD-B to execute the script and you should see the output:
Hello world [Finished]
Another helpful thing is to configure Sublime to be used from the command line. Open a terminal and create a symbolic link:
sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/bin/subl
Now you can change to the directory of you project and with “subl .” Sublime opens the current directory as a project.
To get an overview how CoffeeScript compares to JavaScript check out the docs. Further I’ve read CoffeeScript: Accelerated JavaScript Development which gives a good overview of the language.
Update: Great link explaining some Sublime features/shortcuts 9 reasons you must install Sublime Text 2. Code like a man, man.
Recent Comments