Skip to content

Instantly share code, notes, and snippets.

@OscarGodson
Created November 9, 2011 18:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OscarGodson/1352509 to your computer and use it in GitHub Desktop.
Save OscarGodson/1352509 to your computer and use it in GitHub Desktop.

#Why I Don't Use CoffeeScript

CoffeeScript in of itself, and not as a transpiled language, is slick. The problem for me is what it's supposedly "fixing".

##Syntax Sugar

For a Rails and Python developer JS is ugly (as I hear). You have... dun dun dun, curly brackets and white space doesn't mean anything (oh the humanity!). But, I like my whitespace. I like not being restricted on how I write my code aesthetically. Not to mention CoffeeScript is by far less human readable than JavaScript. Programming languages, IMO, need to be a good balance of both human and machine readable. Simple example:

cube = (x) -> square(x) * x
cube = function(x) {
  return square(x) * x;
};

Even if you've never programmed before the 2nd example would make sense. The first would make you go "WTF?!". I guess if you were writing 1000s of lines of code every single day from top to bottom typing less would be important, but we're humans, not computers, so legibility is far more important than saving a few keystrokes.

But, more than all of this what bugs me is the fact it's a completely transpiled language for syntax sugar. What an awful reason. So, on to the next reason...

Related: http://oscargodson.com/#!/article/55075016

##Wart Removal

Another thing people always bring up is that it fixes "warts" in JavaScript. Things like for...in loops and they give examples like this:

for (var key in obj) {
  if (obj.hasOwnProperty(key)) { // only look at direct properties
    var value = obj[key];
    // do stuff...
  }
}

First of all... no. Just use a for(i=0;i<=10;i++). There's no wart removal there and many of the other examples I've seen are like this. That's just trying to prove a point. I find wart removal to be a awful selling point. In other words you're saying "Fuck the need to learn how to write JavaScript, we'll fix it for ya." You really need a transpiled language to save you some time from learning the right way to write JavaScript in the first place? Learn JavaScript's pain points and just don't do them.

It's like that C/C++ quote goes:

"In C++ it's harder to shoot yourself in the foot, but when you do, you blow off your whole leg."
— Bjarne Stroustrup.

##Classes

I hear a lot about the love of how CoffeeScript handles classes and writing classes is a pain in JS. In that case, use a small library. You don't need an entire transpiled language for it! For example here's what you can do with a pretty tiny script:

var Ninja = Person.extend({
  init: function(){
    this._super( false );
  },
  dance: function(){
    // Call the inherited version of dance()
    return this._super();
  },
  swingSword: function(){
    return true;
  }
});

From: http://ejohn.org/blog/simple-javascript-inheritance/

##Conclusion

After everything, CoffeeScript is purely for people who like looking and reading Rails like code. JS warts should be avoided by education, not by simply ignoring them and cool features like how CS handles Classes, or even loops, can easily be fixed with a much smaller codebase and no need to compile by using a simple homebrewed library or something like underscore.js, jQuery, etc.

P.S. People who write CoffeeScript specific codebases/libraries/etc and name them like "mylib.js"... i hate you. *cough*batman.js*cough*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment