By Michael Woloszynowicz

By Michael Woloszynowicz

Sunday, November 6, 2011

CoffeeScript Means Giving Up on JavaScript

While many of you will probably disagree with me, I find the trend towards writing in languages that compile to JavaScript somewhat alarming. The most notable of these languages CoffeeScript, and it's one that has gained a good degree of traction over the last year or so.

While I like and applaud the intention of these languages, I question their necessity and worry about the knowledge gap they create. More importantly, they all fail by requiring that you be an expert in two languages. Let's face it, you can't just program CoffeeScript without knowing JavaScript, unless you're willing to defer debugging to someone who does. If we're already willing to learn both languages and then spend time reading and debugging compiled JavaScript, why not just write good JavaScript from the start? For the extra effort you'll make learning CoffeeScript and its idiosyncrasies, why not put it towards really learning JavaScript?

The problem is that many programmers are turned-off by the lax nature of JavaScript and translate this into a shortcoming when writing large JavaScript applications. What you're really doing is giving up on a language that is brilliant for that very reason. Sure JavaScript has its share of problems, but they are all issues that are workable given enough knowledge and the use of a proper framework.

While frameworks help, some also serve to propagate this JavaScript stereotype. jQuery is a perfect example, as it does a brilliant job of eliminating cross-browser inconsistencies and makes DOM manipulation a snap, but does little to improve the overall structure of your application. A relatively small number of companies have sought out frameworks that aim to address the spaghetti problem, while the rest quickly realize that their jQuery code has become an unreadable mess. The reason these things happen - and it's the source of most problems with JavaScript - is because people simply don't know JavaScript. I've written at length about the JavaScript knowledge gap and the ad-hoc school of learning so I won't dwell on it here, but I urge you to ask yourself whether a move to CoffeeScript is sign that you've given up on learning it properly? Is it a problem with JavaScript or a lack of understanding?

As of writing this, I've written more lines of JavaScript than I care to admit. In fact our entire web front-end is written in JavaScript, and not once has our team had problems with maintaining our JavaScript code. In fact, despite our massive JS code base, we rarely have problems caused by the very things that CoffeeScript aims to eliminate. The main reason for this is that we've enlisted the help of a framework that brings structure to our application. Our choice was Dojo but you could also choose Require.js (a close relative of Dojo's class system), backbone.js, the Sencha framework, and many others that you can use in combination with jQuery (if you so desire). The other reason is that we've forced our developers to gain a deeper understanding of JavaScript and built a set of best practices that everyone follows which help to produce a consistent and high-quality result.

Before you delve into the world of "compline to JS" languages, I urge you to check out some of these structural frameworks, pick up a copy of JavaScript the Good Parts, and re-evaluate your decision. If after all this you still feel that the syntactic advantages of CoffeeScript et al. warrant the move, then by all means dive in. I simply ask that you enforce a good degree of JavaScript knowledge from your coworkers, and make the move for the right reasons, not because you're running away from JavaScript. JavaScript is the language of the web, and its understanding is further jeopardized by delegating another language to write the code for you.

If you liked this post please follow me on Twitter for more.


  1. You're certainly right about the debugging aspect of coffeescript, in the end unfortunately browsers currently give you no help to debug obsfucated and optimized code, although chrome does provide a source formatter for free. I have also heard something about upcoming development tool improvements for higher languages coming in either chrome or Firefox, can't recall the source sadly so take it as you will.

    I think the biggest appeal of CS for me is in doing more with less. For example in CS an anonymous function which retains the current context is only two characters (=>) where it is a lot more in plain Javascript.

  2. CoffeScript is an improved tool. Javascript is the original tool. It creates clarity and simplicity and abstraction - which can be beautiful.

    We still have to know our tools - the complexity and the intricacy and all of the details are always below the surface.

    Creating tools that improve our experience as developers is a common practice - this i why we don't program in assembler. We are constantly refining our tools.

    Just because it is a great idea to know and read Javascript the good parts - as it is a good idea to follow careful programming practices - we can improve in many areas.

    Readability and consistency is the gift that coffeescript offers.

  3. It sounds to me like you haven't really tried out CoffeeScript Michael. Programming in CoffeeScript has made me like, understand and love JavaScript MORE, not less. Unlike GWT, Dart or ClojureScript (which are all fine technologies), CoffeeScript is still JavaScript at it's soul, just with more syntactic sugar. One can't eat sugar all the time, but it's okay to indulge yourself occasionally.