Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

CoffeeScript: A New Language With A Pure Ruby Compiler

By Peter Cooper / January 4, 2010

coffeescript.png CoffeeScript (GitHub repo) is a new programming language with a pure Ruby compiler. Creator Jeremy Ashkenas calls it "JavaScript's less ostentatious kid brother" - mostly because it compiles into JavaScript and shares most of the same constructs, but with a different, tighter syntax.

Interesting trivia: Jeremy was inspired to create CoffeeScript based on code he saw while reading Create Your Own Programming Language by Marc Andre Cournoyer!

To get a feel for the language, check out this example code (CoffeeScript on the left, resulting JavaScript on the right):

cofeescriptdemo.png

As a Ruby project, you can get the CoffeeScript compiler installed with a simple gem install coffee-script or check out the code from/on GitHub. The code is worth a look as it's notably quite vanilla with hand crafted Ruby covering the lexer and code generation and Racc built code for the parser.

Comments

  1. sasuke says:

    really nice project. in github there is like example the rewrite of underscore,js in coffee

  2. Jeremy Ashkenas says:

    For folks who'd like to see where the language is headed, I'd recommend checking out the source and running "rake gem:install" -- I'm hoping to have version 0.2.0 out soon, which includes significant whitespace, object comprehensions, better conversion of statements into expressions, and a whole host of other goodies, most of which you can read about here:

    http://github.com/jashkenas/coffee-script/issues/closed

    Have fun.

  3. Ric Roberts says:

    Hi Peter. Good post - this looks interesting.

  4. Juvenn Woo says:

    Seems everything in CoffeScript is an object, function is, too. Right?
    It's cute!

  5. Jonas Nicklas says:

    I've created a very simple plugin for using CoffeeScript from Rails, might be useful:

    http://github.com/jnicklas/bistro_car

  6. Benedict Eastaugh says:

    Juvenn: as in JavaScript, yes, functions are objects.

  7. Zach Dennis says:

    This looks very interesting indeed! Very cool project Jeremy, great post Peter,

  8. batman says:

    you have to explain what is the differnce between this and Ruby. i.e why should someone use this new language ? what are the benefits?

  9. Beoran says:

    Although Coffeescript feels a bit pythonic, it's a nice idea. Makes me wonder how the various Ruby-to-Javascript compilers are doing.

Other Posts to Enjoy

Twitter Mentions