Jun
19
2011
The best thing about JavaScript is its implementation of functions. It got almost everything right. But, as you should expect with JavaScript, it didn’t get everything right.
~ Chapter 4. Functions, Douglas Crockford’s most read, JavaScript – The Good Parts
Jun
04
2011
It’s been couple of weeks I have started using CoffeeScript (I know it has awesome integration with Ruby on Rails and particularly Node based projects) and I have fallen in love with it.
It’s not like that I don’t like JavaScript but JavaScript is a hard language. I think JavaScript is one of the language that most programmers have used in some ratio and most will say claim they know that language and most of the time it may be kind of wrong assumption.
For those who haven’t used CoffeScript, its a Ruby inspired language (or micro framework) that compiles into JavaScript.
Go and check the site if you haven’t! http://jashkenas.github.com/coffee-script/
I’ve been using CoffeeScript for couple of projects now. JavaScript source (http://cdn.sailthru.com/horizon/v1.js ) for Horizon, Sailthru‘s behavioral tracking product is generated using CoffeeScript and another one is work in progress, Node.js client for Sailthru API.
Not to forget that CoffeeScript makes using Node more fun!
Here’s dead simple Node server using CoffeeScript:
server = require('http').createServer (request, response) ->
response.writeHead 200, {'Content=Type': 'text/plain'}
response.end 'Hello World'
server.listen 9999
console.log 'Sever running at http://0.0.0.0:9999'
And generated source code:
(function() {
var server;
server = require('http').createServer(function(request, response) {
response.writeHead(200, {
'Content=Type': 'text/plain'
});
return response.end('Hello World');
});
server.listen(9999);
console.log('Sever running at http://0.0.0.0:9999');
}).call(this);
I like the fact that CoffeeScript makes you hard to have global variable because everything is wrapped inside an anonymous function. And of course you can always use global variable in the form of attaching to window object in JavaScript and attaching to exports object for Node systems.