CoffeeScript: JavaScript Elegantly Refactored

Over the last few years, JavaScript has gained popularity with ever increasing speed. It has gone from being the “Red Headed Stepchild” of programming languages (as described by its creator, Brendan Eich), coded in ten days flat, and now ubiquitous in browsers, on servers, and inside smart phones. JavaScript fluency is increasingly essential for anyone doing anything for the web, yet for all the advances in adoption, JavaScript is full of syntactic and behavior weirdness … full of hidden gotchas, odd special cases, and counter intuitive idioms.

CoffeeScript is “a little language that compiles into JavaScript” . CoffeeScript syntax is pragmatic and elegant, borrowing ideas from Ruby, Python, and elsewhere. CoffeeScript tackles the problems in JavaScript, but leaves its roots intact. The end result is a language that is elegant, readable and something you'll look forward to coding in.

Sure, Google and many others have proven that you can accomplish amazing things in JavaScript: but that doesn't make the language any prettier, or any easier to code in. Ordinary JavaScript leaves you open to any number of trivial coding errors that can cause you lots of grief at runtime; a missing comma, an extra newline, and suddenly your code does something completely wrong.

CoffeeScript grafts a new syntax onto JavaScript that works better with JavaScript's fundamentally functional nature, such as list comprehensions, function binding and destructuring assignment. It also adds features that really quickly become dear to you, such as string interpolation, heredocs (multi-line strings), extended regular expressions, and a proper class system.

CoffeeScript also includes a fair number of wonderful heresies … such as jettisoning the curly braces of the C language world in exchange for Python-style indentation. In CoffeeScript, every statement (even an if … then) is an expression whose result can be stored, and every function returns a value.

Despite all these features; CoffeeScript is fully interoperable with JavaScript, so you can easily use it with jQuery, Underscore, or whatever other frameworks you have cooking: browser-side or server-side. And for all the cool stuff it adds, the mapping to JavaScript is close enough that debugging is not a great challenge.

Whether you dabble in a bit of client-side logic or are hip deep in NodeJS, you owe it to yourself to take a peek at this elegant language that lets you keep what you like about JavaScript and improves on everything that makes you want to pull your hair out!


About Howard Lewis Ship

Howard Lewis Ship is the original creator of the Apache Tapestry project, and is a noted expert on Java framework design and developer productivity. He has over twenty years of full-time software development under his belt, with over fifteen years of Java. He cut his teeth writing customer support software for Stratus Computer, but eventually traded PL/1 for Objective-C and NeXTSTEP before settling into Java.

Howard has been developing financial and e-commerce applications in 100% Clojure since 2012.

Howard currently works for Wal-Mart's Global E-Commerce division. He lives in Portland, Oregon with his wife Suzanne, and his children, Jacob and Olivia.

More About Howard »