Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"Just like JavaScript but nicer to type." was a decent pitch to make CoffeeScript sound safe. But it's become so much more. And you get past the simplicity of that pitch quickly if you use CoffeeScript earnestly.

Going through the Table of Contents on http://jashkenas.github.com/coffee-script/ I've picked out the features of CoffeeScript that make it a different beast than just a JavaScript without warts.

* Lexical Scoping and Variable Safety * Conditional Assignment * Splats * Comprehensions * Everything is an Expression (&implicit return) * The Existential Operator * Classes, Inheritance, and Super * Destructuring Assignment * Function binding * Chained Comparisons * Extended Regular Expressions

This is beyond a simple sweetener for your JavaScript code. Yes, you could write your JavaScript like you write your CoffeeScript, but you wouldn't.

Try this little jewel in Try CoffeeScript and you'll see what I mean:

[open, contents..., end] = "<impossible>".split "" alert contents.join ""



I think the jury is still out on whether or not the existential operator is too clever for its own good (in particular when used as part of a chained expression).


What is so clever about a nil object check?

I suppose if you're using it to make skirting the "Law of Demeter" and thats something you don't want to do it could seem like something bad.

But I'll take "foo?.bar()" over "foo.bar() if foo" gladly.


The issue is in an expression like "out = foo?.bar()". What I want is to only assign to out if foo exists, but the compiler has no way of knowing that-- it'll evaluate to undefined instead. In this situation I need to use "out = foo.bar() if foo".

That's easy enough to remember, though.


Yeah, I can see the argument in favor of it. Easy to miss when reading through code, but arguably unlikely to be used on a way where it would really matter if you missed it while scanning.

I found myself trying to decide whether or not to use it the other day and decided for now it was too clever. So I guess the jury is out in my own head, maybe not in anyone else's.


I find it quite useful in Io, including chained expressions.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: