Justin du Coeur (jducoeur) wrote,
Justin du Coeur

Language du Jour: CoffeeScript

Stumbled across in the context of a scala-debate discussion, I find the CoffeeScript language. This one's not quite as take-over-the-world high-concept as most of the ones I enthuse about, but looks unusually pragmatic. As it describes itself, it is "a little language that compiles into JavaScript".

Really, it's not so little -- it's a fairly high-level language with a lot of good concepts -- but it's not trying to be all things to all people. Mostly it's adding a bunch of common concepts and a lot of syntactic sugar to provide a less painful way to write serious Javascript. It is very explicit about being a layer on top of JS: indeed, all of the CoffeeScript examples show precisely what JS they compile into. That said, the language looks in many ways more pleasant and easy-to-use than JS.

It has its quirks, some of which aren't *my* quirks: for example, it picks up Python's fondness for using line breaks and indentation to express code structure, rather than hard delimiters, and Perl's fondness for postfix conditionals. And in some cases I'm not certain I like their decisions -- for example, they talk a lot about having comprehensions, but it's not obvious that they have a way to distinguish lazy vs. eager ones. (The examples all appear to be eagerly evaluated.)

That said, those complaints are relatively minor: in general, this just plain feels like a more modern language than JavaScript. And I love the fact that you not only can compile it into Javascript offline, you can even just write it into your page source and compile it on-the-fly in the browser if you don't mind a bit of overhead. (The reference page actually does this: the page's code is in CoffeeScript, and is compiled when you load the page. That's quite neat -- I didn't even know you could define new script languages on-the-fly like that.)

I haven't done anything with it yet, but this seems well worthwhile for anyone who is facing a complex JavaScript problem. In general, this looks likely to produce cleaner, more concise and more maintainable page code than plain JavaScript would...
Tags: programming

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded