Why I Prefer JavaScript Over CoffeeScript

30 commentsWritten on September 11th, 2011 by
Categories: JavaScript, Opinions

CoffeeScript has gotten pretty popular in the past 6 months or so. If you're not familiar with it, be sure to check out the language's website. It's basically a language that compiles to JavaScript. So you can write your client-side code in CoffeeScript, but still have the browser execute the resulting JavaScript. Or if you're using Node.js, you can just use CoffeeScript instead of JavaScript if you prefer. It doesn't matter, it's all JavaScript in the end.

To the many people who dislike JavaScript, either because of its syntax or its many pitfalls (or both), CoffeeScript is obviously great. They can get in on all the fun and progress that's happening in the JavaScript world, without having to write JavaScript themselves. Purely from a syntactical point of view, it's hard to argue the merits and benefits of the language. I'm fond of Ruby's syntax, so instinctively CoffeeScript looks much more appealing to me than JavaScript. Despite the nice syntax and protection from JavaScript's pitfalls, I still prefer to code in JavaScript.

For starters, if you're doing JavaScript development (whether client-side or server-side), you're likely to use a variety of scripts or libraries written by people other than you. While some libraries are documented very nicely, others aren't. In many cases, I still find the ability to read the source code of a library I'm using to find what I want to know to be a very valuable benefit. I've noticed that I often do this when trying to find out how to do something that I can't find in the documentation, or when I'm troubleshooting something. If you're not familiar with commonly used JavaScript patterns, this becomes harder than it needs to be. Some subtleties might pass you by, or in some cases you might have outright difficulties comprehending the code. Of course, reading JavaScript code from seasoned JavaScript developers can also be a great learning experience about how to properly use the language. Yes, there's a lot of bad JavaScript available, but there's a lot of beautiful JavaScript around as well. I'd say the benefits you can get from reading the code of the libraries you use are directly dependent on your familiarity with JavaScript as a language, as well as its most common used patterns and idioms. If you try to avoid JavaScript by sticking with CoffeeScript, you sort of limit the potential benefits to be had from a tremendously valuable resource.

Another reason is that JavaScript is gradually becoming ubiquitous and that's all the more reason to maintain your familiarity with the language. You're unlikely to build a website without a nice dose of JavaScript, either used directly or through CoffeeScript. Server-side JavaScript usage is on the rise, and the growing popularity of Node.js is only going to increase the usage. True, you can use CoffeeScript with Node.js as well, but keep in mind that you're going to be reading a lot of other people's JavaScript code when you work with Node.js. That's not a slight at Node.js as a platform or development community btw, I very much enjoy working with it and am loving the learning experience. JavaScript is also being used in a few NoSQL databases, and in those cases it's harder to avoid it. Who knows where JavaScript is going to be used in the future? Will you always have the ability to 'compile' your CoffeeScript code to JavaScript in order to take advantage of whatever new environment where it can be used? Maybe you will, maybe you won't. Who knows? What you do know is that the vast majority of documentation and information you're going to find on the internet will be using JavaScript. Again, all the more reasons to become proficient in JavaScript IMO.

Then there's the aspect of debugging and troubleshooting. While you can indeed 'compile' your CoffeeScript code to JavaScript, none of the debuggers available at the moment transform your code back to CoffeeScript at runtime if you're trying to debug something. Ok sure, we all prefer to avoid debugging by writing proper tests but the fact of the matter is this: if something goes wrong, I certainly want to understand the code that I can debug. And even more so, I want that code to be readable and not look like it was generated by a tool (and I'm not talking about a lousy developer). Or if I receive a stacktrace from a tester or (gasp) a user, I would like to be able to look at the code that is listed in the stacktrace without thinking "oh crap, what the hell is going on here? I'm not used to all this JavaScript!!".

Again, I have no issues with CoffeeScript as a language. I like its syntax and the ideas behind it. But for me, that just doesn't outweigh the downsides that I've listed here so I'll be sticking with JavaScript for quite a while longer, me thinks.

  • Pingback: Elegant D » Why I Prefer JavaScript Over CoffeeScript

  • Robin van der Knaap

    I always found the idea of adding an abstraction layer over javascript not very desirable, your article nicely explains why.

  • vbedegi

    I agree, it’s not desired, but only when the abstraction hides JavaScript idioms. I mean, like GWT or Script#, which completely hides the dynamic nature of JS. On the other hand, CoffeeScript is just syntactic sweetness over JS, saving You from lots of syntactic noise.

  • Anonymous

    I agree with the readability issue. CoffeeScript hasn’t been around long enough for a majority of devs to pick it up or adopt it. Don’t agree with usage though. Wherever you can use JavaScript, you can use CoffeeScript. That’s the whole point of the compiler emitting JavaScript code that’s not only readable but also complies to JSLint. Same goes for debugging as everything underneath is plain-old JavaScript. 

    My recommendation is not to choose one or the other. Learn both languages and learn them well. 

    • http://davybrion.com Davy Brion

      You’ve been playing around with JavaScript for a while now, so yeah, to you the generated javascript is readable.  To someone who forgoes learning it properly, i don’t think everything is going to be as crystal clear as it would be if it were coffeescript

      • Anonymous

        One can say the same about SQL and NHibernate. I always recommend to first learn JavaScript and learn it well after which one can jump over to CoffeeScript/ClojureScript or whatever else. 

      • http://murrayon.net/ Mike Murray

        That point right there probably should have been in your blog post. Learn JS first, then there’s nothing wrong with CS (only goodness).

        • http://davybrion.com Davy Brion

          The problem is that most people will just jump on CoffeeScript because of all the hype because they’ll think it’s not worth learning JavaScript, precisely because they think CoffeeScript takes away that need

          • Artsrc

            You are argument learning/using CoffeeScript does not benefits of learning JavaScript.  CoffeeScript is better than JavaScript.   Therefore the ideal is that CoffeeScript takes away the need to learn JavaScript.

            How do we get there?  Maybe:

            1.  CoffeeScript source debuggers.
            2. Native CoffeeScript support in places where JavaScript currently appears
            3. JavaScript to coffeescript compiler for legacy sources.  Preferably on the fly/dynamic.

  • http://twitter.com/dagda1 dagda1

    JSLint compliant code, higher readability, list comprehensions and pattern matching. I could go on.  What is not to  like?

  • http://twitter.com/msuarz mike suarez

    yeah abstractions just get in my way … i miss the assembly days

    • http://davybrion.com Davy Brion

      apples vs oranges

  • Pingback: The Morning Brew - Chris Alcock » The Morning Brew #935

  • Thomas Coats

    Summary of above article for TLDR:

    1. Stuff is written in javascript, therefore use javascript.
    2. You might not be able to use coffeescript in some situations, therefore use javascript.
    3. The debugger will show javascript, therefore use javascript.

    I think that a rough understanding of every layer from the CPU up to the language you are using is very useful as a developer. At the very least an understanding of the layer beneath the abstraction you are currently working with means a developer will appreciate the tools and techniques they have available.

    For example understanding that certain method calls will box variables and unbox them in .NET is useful information. It’s not, however, necessary.

    I think the real argument to be made is against developers who don’t have a solid foundation. It’s not enough to start from the top – with a abstract language. To be a great developer you will want a good understanding of language and how it works, and why it works.

    Anyway, controversial point but I’m still in love with CoffeeScript. Perhaps CoffeeScript is a language for people who appreciate it? Developers who have done the hard yards in Javascript and know exactly what CoffeeScript is giving them?

  • David Hayden

    Yes, +1 for CoffeeScript.

    Your arguments are more generic in nature about not using a layer of abstraction, tool, or library unless you completely understand it. We could easily write a similar post about LINQ, for example, and how people should really understand the T-SQL hitting the database.Obviously if you don’t know JavaScript and JavaScript best practices / patterns you have no right to be using CoffeeScript. In fact, you won’t really appreciate CoffeeScript anyway since you will have no idea as to its benefits.

    However, for those who know JavaScript and use it to craft JavaScript Web Apps, it makes the developer much more productive, makes applications easier to read and maintain, and emits JavaScript that adheres to best practices and patterns.

    • Anonymous

      Can pain in the *** debugging be considered beneficial.

  • E.Z. Hart

    I remember when this argument was called “Why I prefer assembly language over C” :)

    • http://davybrion.com Davy Brion

      i don’t think you payed much attention to that argument because it is entirely different from this one ;)

      • Alek Szenfeld

        Not as far as it might appear though

  • Liam Mclennan

    If we agree that it is essential to know JavaScript, even if you are using CoffeeScript, then what’s your point?  

    • http://davybrion.com Davy Brion

      i’m just stating preference, i think i’m allowed to do that and nobody’s forcing you to read this or agree with it

      also: how great would this industry be if people always took the time to learn what’s essential vs just trying to be productive? one can only imagine, i’m afraid…

  • Neuruss

    Coffeescript is not a whole new language, it’s just an alternative syntax for Javascript. It compiles to highly readable javascript and generates fully compliant JSLINT code. So it offers much more than a nicer syntax, it fixes javascript’s inconsistencies (sorry for my bad english).

    CS doesn’t add different data types or data structures. You use javascript arrays and objects. It’s data model is exactly the same. The only difference is the beautiful, succinct and expressive syntax that let you manipulate these data structures.

    In the end, resistance is futile. You will be assimilated… 

  • Russell Xohdare

    Found your take on this interesting — but there is a little bell that keeps going off in my head — There was a time when programming in assembly, C and C++, one would have tended to look questioningly at those who proceeded towards more abstract languages. Then came Java with its garbage collection, etc, that now, itself, has several derivatives that run on its JVM – such as Scala, and then came the at one time abomination to hard core programmers – JavaScript from which we now see frameworks + abstractions such as jQuery. With all of these, among many, the same questions and put downs have always been repeated.

    Yet, each has, in fact, brought particularly strong rewards to the table, and each has become, according to requirements, necessary to learn… Most seasoned programmers these days, have to have a toolbox of languages – though arguably similar, running 5,6,7 or 8 deep. If you want to keep working – dexterity is what is required. 

    To base an argument less on the capabilities of the language and more on its syntax differentiation, abstract nature and traditions, can in fact be very dangerous. 

    Also using your NoSQL argument here would possibly be deemed inappropriate – bearing in mind that most projects in that arena – here thinking of Cassandra, HBase, MongoDB, etc, would be gunning for the type of heterogenous server side efficiencies that have a lot more powerful and appropriate alternatives to J*S*. Though one must admit that, the philosophy of, to a man with a hammer – every problem is a nail, may take hold, it is not one that should be encouraged –  it limits the individual.

    The question I would have liked to have seen answered is — “What exactly is CoffeeScript trying to do and does it achieve that effectively without impacting on the nature or capabilities of JavaScript.” What I see above is more a statement of limitations you are self-imposing than anything else…

  • Sssssmokey

    You really have to know what the coffeescript will compile to to even write coffeescript properly.  You can never avoid javascript, but you can avoid writing about 1/3 of the boilerplate punctuation.  It’s a horrible idea for beginning javascript developers to use it, but once you have a very good familiarity with javascript IMO it’s just silly to continue writing every little brace and for loop.  Coffeescript is MUCH easier to read than javascript also, leading to easier to understand and more error free code.  It also deals nicely with the issue of global variables (by wrapping each scope automatically if it needs it) without the coder needing to write var.  Sure I need to know it is there behind the scenes, but if I have to explicitly write it each time that is just one more potential bug to fix.

    Just my 2 cents as someone who writes JS every day.

  • Pingback: CoffeeScript or JavaScript ? | phato.blog

  • http://www.facebook.com/eliranmal Eliran Malka

    i don’t believe using coffeescript will dull your brain into forgetting javascript, i do believe that – much like any other library / framework / code snippet – you should use it as an enhancement to your skillset, not as a crotch. 
    responsibility is the key.

    • Anonymous

      Yes, you definitely don’t want to use coffeescript as your crotch

  • garek007

    Thank you, thank you, thank you, thank you. You said exactly what I was thinking. I’m tired of people trying to make JavaScript easier for people. If you need client side actions, learn the damn language. People should stop trying to cater to those that don’t know it. Meanwhile it cheapens the years I’ve spent learning JavaScript, and screws me even more, because I JUST got into jQuery. So what, now I have to learn yet another mini language? It’s ridiculous! I learned JavaScript, now I’m learning jQuery, now I’m supposed to add yet another one to the mix, one that doesn’t even look like JavaScript?

    If jQuery was supposed to make our lives easier, why do we need CoffeeScript!

  • ohcibi

    > none of the debuggers available at the moment transform your code back to CoffeeScript at runtime

    *yaaaaawwwwn*

    back in 1985 there was no parser for php….. so???? whats your point?? time goes forwards not backwards….

    • Antanas Spartanas

      *yaaaaawwwwn*I accept your boring attitude.


      Dear javascripters. Do you remember the very first time you saw The Debugger. Anyone who remembers window.alert() as the only one?