Technically Speaking: CoffeeScript



Developers love to turn simple into simpler. Every year, new programming languages are introduced that try to tweak the most popular languages – Ruby, Python,C++, etc. – into something cleaner, faster, and more accessible. Few, if any, have had the success of CoffeeScript, invented in 2009 by Jeremy Ashkenas

CoffeeScript compiles code into the widely-used JavaScript language using a minimal syntax inspired by Ruby and Python. For example, JavaScript’s “this” becomes an @ symbol in CoffeeScript (yes, it’s only three characters shorter, but such tricks can save hours). Also, CoffeeScript only makes use of a curated selection of JavaScript features, avoiding some of the language’s oddities that can befuddle new developers. Ideally, using CoffeeScript is like writing in shorthand, which is then translated into a better language than the original.

Ashkenas argues that CoffeeScript enables developers to “write what they mean, instead of writing within the limits of historical accident.” He means that CoffeeScript allows for simpler, declarative functions that do not require JavaScript’s quirky syntax. And writing in CoffeeScript can often reduce the length of code for a project by a third.

Still, a new language is only as effective as the community that fosters it. There is an ongoing, healthy debate about the usefulness of CoffeeScript, and the language has plenty of detractors. Specifically, some say it makes debugging a pain, and that verbally readable code doesn’t make it more easily understood. But the language’s inclusion as a default in Ruby on Rails 3.1 last year bodes well for its future.

Perhaps a newer variation – LatteScript? – will succeed it. Perhaps the JS faithful will never fully embrace it. In any case, CoffeeScript has already left its mark.

Related terms to know: Syntax, Ruby on Rails, JavaScript, Python