Monday, 4 March 2013

Let's try CoffeeScript


I've been always interested in JavaScript - so it's getting even more when is about compilers. I've been keeping half an eye on the competitors lately: Dart, CoffeeScript, GWT and TypeScript.
Here you are a quick chart from Google Trends:
Don't look at the numbers, that's a very early result from 2008. Look at the current stand. CoffeeScript is highly on the top. To be really honest I'm a theoretical Dart fan. Dart is kind, Dart smart, Dart is important. It know everything that is necessary for a JS abstraction layer - and was on the right path. No idea what's happening. It seems they are still working on it but I miss the buzz lately.

TypeScript is pretty much Microsoft flavored and the website is designed for IE, so I don't think we should spend more time with it at this stage.

GWT is still probably the top level carnivore on the field, but that is definitely not for a tired night to try out. I've did some small GWT projects and it's a joy to work with it.

So CoffeeScript. I'm not gonna copy-paste the tutorial, you can check it out also. It has a basic structural abstraction, such as functions, classes, literal grouping. And it has a nice functional flavored extension embed in the language, which is always nice, like a free lollipop. And let's not forget about that's it's pretty dense.

The workflow is also simple: you write your code in CoffeeScript syntax and compile it with an appropriate tool - such as the Node plugin. I just fired up PHPStorm and added the CoffeeScript support. Then I installed the Node plugin and compiled my sample file - works as expected.

What I'd like to do is to convert the daily-time-cutter project to CoffeeScript so I can see it's working on a real code as well. My biggest fear is how easy to make it work with jQuery, the whole library. CF can accept plain-old JavaScript code without any problem - I mean, khm, by eval. Which is unacceptable.

We'll see. Hope I can show you some diffs tomorrow.

---

Peter

Ps.: I've just my friend's (James) blog where he created a game in Coffee - it's amazing! You have to check that out.

No comments:

Post a Comment