Coffeescript vs. Javascript: Dog eat Dog

I’m happy to say that I’m now an official los techies “techie”!  Thanks to Chris Missal and all the other amazingly smart people who let me join the Los Techies crew.  Without further ado, this article is going to focus on the pros and cons of javascript vs coffeescript.

The Case against Javascript

Javascript has a bad reputation of being a flaky scripting language, because let’s face it, that’s exactly how it started out.  There are a number of let’s say, quirks, in the language that make most developers cringe:

  • Strange type coercision and overloading of +
  • Strange results for equality testing == or ===, != and !==
  • Prototypal inheritance vs. class based object orientation
  • Noisy syntax, lots of curly braces, function keywords, and semicolons
  • Global variables are as easy a missing a var statement
  • Lack of any sort of design aesthetic
  • Lots of bad javascript progammers (think graphic designers)
  • Lots of bad javascript code (think code that a graphic designer would write)
  • Hundreds of implementations for every browser, version and other javascript dependent platform (and yes, some of them are buggy)

Now those last three are more a reflection of the javascript ecosystem than the language design, but they are worth a mention, because they contribute to javascript’s overall poor repuation.

There’s actually some great stuff about Javascript

While javascript may look gnarly on the outside, there are actually some pretty nice features from a semantic standpoint:

  • Awesomely dynamic (basically you can do anything you want, type safety and common sense be damned)
  • Top-notch functional programming
  • Largest community of developers
  • Largest install base on the planet
  • No corporate ownership of the standard
  • Sophisticated javascript runtimes (most modern browsers, node.js etc)

Coffeescript:  It’s Better than Javascript right?

A few years ago, coffeescript jumped onto the scene as an alternative to straight-up javascript. (If you want to take a closer peak at the syntax, then I advise you checkout their site, coffeescript.org.)

CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.

What a novel idea!?  A precompiled language that fixes all of the nastiness and awkwardness of the javascript language.

Well, it turns out that it’s not that simple.  Here’s an excellent rant/explanation of why coffeescript is not so great.

The Subjective Argument against Coffeescript

The subjective argument against coffeescript can be summed up pretty easily:

Do you like C-style syntax or Ruby/Python-style syntax?

Coffeescript was designed in the vein of Python and Ruby, so if you hate those languages then you will probably hate coffeescript.  As far as programming languages go, I believe that a developer will usually be more productive in the language that they like programming in.  This may seem like a no-brainer, but there are quite a few articles out there trying to argue the objective truth of and vs &&.

The Hard Objective Arguments against Coffeescript

Here are what I consider the most pertinent arguments against coffeescript.

  • Added debugging complexity
  • Added compile complexity
  • Smaller development community

How to Decide which language for your Project

I’ve worked on large projects in both javascript and coffeescript, and guess what?  You can build an application in either one, and your decision of javascript or coffeescript is not going to make or break you.

If you are working on a project by yourself, then I would pick whichever language you prefer working in.  It’s totally subjective, but you are going to be more productive coding in a language that you like coding in vs. one that you hate coding in.

Now, for the tricky part.  What if you’re working on a team?

Coffeescript ate my Homework

This is where coffeescript can be a huge problem.  If you are working with a tight group of skilled engineers, and you decide to work in coffeescript, and everyone is on board, then my opinion is that you might very well end up being more productive.  Especially with programmers that have a Ruby or Python background.

However, for projects that have a revolving team of contractors or that have junior developers that hardly understand the semantics of javascript to begin with, then I would say watch out!

This may seem paradoxical, but I think part of the problem comes back to the debugging cycle.  Debugging is a critical part of learning a new language, and for someone with a good javascript background, the coffeescript debugging problem shouldn’t be that much of an issue.  However, for a noob, it can be a killer.  They don’t grasp if their mistakes are part of coffeescript or javascript which leads to major time sinks on very mundane syntax errors.

In short… it depends :)

 

 

Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Brad Carleton

Brad is a rockin' fun JavaScript coder who enjoys building cool stuff and long walks on the beach. As the Founder/CTO at TechPines, he has worked with large companies and startups to build cutting-edge applications based on HTML5 and Node.js. He is the creator of Bone.io, a realtime HTML5 framework, and is the author of Embracing Disruption: A Cloud Revolution Manifesto.
This entry was posted in coffeescript, javascript. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • mshertzberg

    I’m all for whatever works in the context of what your doing. I think it’s silly to have grudges against a language because it’s not trendy. Personally my nipples get hard for the minimal effort of prototypal inheritance, super, and classes in CoffeeScript. It’s hard to `defer` from that when you’re building a super duper decoupled SPA.

  • Chris A Zias

    Hey I have degrees in both Graphic Design and CIS. I’m mostly a UI/UX developer today. I know what you mean about bad javascript code. Javascript was definitely misunderstood for a number of years (and still misunderstood by many today) and as a result many…many people wrote bad javascript. This includes your average programmer with no design background who was quick to dismiss javascript since we were all “forced” to use it and it was “quirky”. In and out like a Marine, and let’s get back to the safety of my server side language of choice where the world makes sense lol.
    I won’t let graphic designers, myself included, off the hook though. I would have to say we all sucked at Javascript equally, but thank the gods for the Internet and increasing knowledge and awareness of this language. It took someone to say, hey maybe we’re doing this wrong. And in programming as we all know, it can always be better, more refactored, more tested.

  • Vincent Franco

    “However, for projects that have a revolving team of contractors or that have junior developers that hardly understand the semantics of javascript to begin with, then I would say watch out!”

    IMHO, if you have juniors that barely understand the semantics of anything that you’re embarking on then it’s “watch out” no matter what choice you make.

    • techpines

      That’s true. My main point is that coffeescript is going to trade some low level syntax complexities for some higher level complexities in debugging and compiling. I like that tradeoff for myself, but I think for the less experienced person that they will have trouble in the short term with the higher level problems.

      Similar to how it’s easier for someone to make a giant jquery mess, rather than use a frontend framework like backbone or angular. Or write in-line sql rather than use an ORM or data abstraction layer.

      And you could say, well you should never do such things. But there are situations where economically, there isn’t enough value to put super A+ guys on every project. And also that’s somewhat subjective, sometimes you have a super A+ guy in C# or Ruby, and he goes to work in another language like javascript, and he’s basically only junior level coder in that language. In a lot of cases, you may want to just deal with low level messy problems, because there is the chance of getting lost in the high level problems.

  • vinspee

    I go back and forth on the “junior dev” thing. Coffeescript does them a service by making loops easier, preventing global scope pollution, etc., but I think that a junior dev is going to have a harder time debugging. That being said, a junior dev is going to have a hard time debugging, period. Junior devs are not going to write good code. They must learn.

    I just moved from a CoffeeScript team to a JS team. I miss coffeescript. I don’t like typing, and don’t understand why someone would want to type MORE. I also don’t understand why someone would prefer:

    `if (theDude = “Jeff Lebowski”) { return giveAWhiteRussian; }`

    to:

    `if theDude is “Jeff Lebowski” then giveAWhiteRussian`

    you’re going to type whitespace anyway, why not use it?

    • Alexei Boukirev

      The former looks like a structured snippet of code, the latter – like a line from a fiction book, in my opinion.

      To me, the ability to see code structure at a glance is more important than saving on typing. I read code more than I write.

      Also, I like Python but … I tolerate indentation style of the language for its other nice dynamic features. I go the same way with EJS vs JADE templates: I know both but prefer the former.

      • vinspee

        what is “a structured snippet”? It’s not a piece of physical architecture that requires nails, trusses, and wedges. It’s language.

        I agree, I read code more than I write, but I can read the latter without any knowledge of the syntactical idiosyncracies of the language.

  • http://www.lawrencesong.com Lawrence Song

    The article(why coffeescript is not so great) you link to said:

    Update: I actually love CoffeeScript now that I’ve been writing it for a year. I hope to write something about my conversion soon.

  • Pherdnut

    I like Python. What I hate is anything that limits what I can do in JavaScript and requires I alter the way I work with JS after having spent 6+ years learning the living christ out of it. I can’t be the only experienced JS dev that’s turned off by this. Why limit your talent pool for fad tech?

  • http://devtools.korzh.com/ Sergiy Korzh

    The main problem with CoffeScript as for me – is that its syntax differs a lot from JavaScript. It’s good for Python/Ruby programmers but increases “learning curve” for those who already knows JavaScript.
    My vote is for TypeScript as a JavaScript replacement.