A seed of truth.• Developer needs evolve, the language does not.• Some folks are tackling complexity with compilers. • Async, strong types, tier-less, language translators, etc.• Precedent: C++ originally compiled to C.• https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that- compile-to-JS
Scoping• All compiled code executes in function scope.• All variables are declared in function scope.• Global variables must be explicitly added to the root context.• Strict lexical scope.
Elegant syntax• Signiﬁcant whitespace.• Concise function declarations.• Concise literals.• Sane inheritance.• Beautiful to read and write.
Excised “Bad Parts”• Equality with type coercion.• The with and eval statements.• Trailing commas in object literals.• “Fall through” switch statements.
Lots of Sugar• Comprehensions, string interpolations, default arguments, multi-line strings, aliases for this and prototype, existential operator, immediate invocation, splats, array and object unpacking, fat arrow, chained comparisons, etc, etc.
Too cute sometimes?• Proliferation of boolean symbols and operators • true/false, yes/no, on/off • true == isnt false• Parenthesis invocation rules are inconsistent (but ﬁne) • Reference: func • Invocation: func(), func(‘aa’), func ‘aa’
Things to watch out for.
Everything is an expression.• Everything is an expression, conditionals and loops included.• Functions return last statements by default.• Becareful to not return the value of loops/conditionals used for side effects. Might incur performance hit.• Ultimately, easy to remember.
In the wild.• Still a fraction of the JS world.• Notable Users • Rails 3.1, Github, 37 Signals, Shopify• Bootstrapped compiler.• Popular in Node & the browser.• Plenty of repos, followers, watchers on Github.
So should you use it?
At least understand it• You’ll face the same problems that motivated CoffeeScript.• CoffeeScript is inﬂuencing the direction of ECMAScript.next• And have some fun.
But I like it.
My CoffeeScript.• http://www.showbomber.com• https://github.com/clutchski/wolf• https://github.com/clutchski/coffeelint