Decision Time

Up to now I've been using CoffeeScript mainly for my tests - such as they are. I find it highly descriptive and easy to read: a must when reviewing a test suite. This instantly brings up two questions:

  • If it's so readable and descriptive, shouldn't you be using it always? Javascript is offensive.
  • It's sad that you think Javascript isn't readable. Do you code often?

I've had equally passionate, stubborn, smart, friendly, and overall lovely devs hit me from either side of the CoffeeScript divide. One friend told me he couldn't read my test suite unless I used CoffeeScript ("what's with the noise dude?") and another ask me if it's possible to see the generated JS so he "could read it with some level of sanity".

I want to reiterate this: both of these guys are well known, super-smart developers as opposed to the thrash/bash crowd on Reddit or HN. These are my friends. Each is suggesting (strongly) I should "choose a side and grab a pistol".

I'm leaning towards that. It doesn't make sense to have both - I want to pick one and move on...

They Keep Pulling Me Back In

I've tried to avoid this decision because, frankly, I think it's overheated and runs the risk of derailing my entire effort here.

Consider: If I choose to go 100% with CoffeeScript, the hard-core JS crowd will ... be the hard-core JS crowd and dismiss the efforts thus. If I go with pure Javascript I'll end up writing (overall) more code - if only for the lack of syntactic niceties from CoffeeScript - as well as alienating the folks who've come to heavily prefer CoffeeScript.

And no - these aren't people who are afraid of anything - they are some of the smartest people I know.This is about the time where I'm reminded:

CoffeeScript is just Javascript. Get over it.

Cheers - consider me the Cow jumping over your condescending Moon. CoffeeScript is Javascript - except that it's not. It's CoffeeScript. It becomes Javascript and I'm well aware of that. Pedantry aside, let's move on.

The only way to intelligently ponder this issue is to distill the rhetoric and see if there's something compelling that I can ... drizzle with my experience. Let's do it.

CoffeeScript Sucks

This seems to be the canonical rebuttal against the use of CoffeeScript. I appreciate the author's candor and detailed approach to what he sees as a shortcoming in CoffeeScript. Let's see if I can work this down to something croonable.

Debugging.

The author points out that debugging a problem involves looking at the compiled JS and then stepping back into CoffeeScript to see where you messed up. This is a reasonable point: by using CoffeeScript you've just added syntactic complexity to your application: You could have a CoffeeScript error during CoffeeScript compilation that you need to solve. This, by definition, wouldn't happen if you weren't using CoffeeScript.

You could have a logic error you need to figure out, and now you're climbing through 2 stacks instead of 1. If you're working in the browser this can be an issue, to be sure - you'll have to debug the generated JS, not the CoffeeScript. If you're working in NodeJS (which understands CoffeeScript) - you can get "odd" error messages returned that lack syntactic guides as to where the problem is. Not a very big issue - but it slows down the overall development process.

Believe it or not - this problem is seen mostly in testing. It takes some time to get the hang of writing CoffeeScript tests and understanding the output if there's an error. Sometimes it's helpful - other times it's simply not. For instance - it's all too common a mistake to use a "var" keyword when declaring a variable in CoffeeScript. This kind of thing is pounded into your head when writing Javascript to avoid global naming issues.

Consider this code here (a mocha test):

If I run this, I receive an error:

Word is not defined? Of course it's defined! It's VAR dude! Oh right - there is no var is CoffeeScript!

Sure would be nice if the error message said that. And yes - it's a bit of a nit, to be sure. But when you read this output when running a test - wouldn't your first inclination be to check your code under test to see if there's a problem?

Notice that I have no line numbers here. I do have a file reference which works - but it's not nearly as clear as the same kind of output from Mocha if you have an error in straight-up Javascript.

This kind of thing slows you down a touch, and it does happen. I don't like going slower.

Readability != Comprehension

One point that's majorly in CoffeeScript's corner is the ability to read quickly what the code is trying to do. This is especially hard in Javascript given the event loop and asynchronous structures the language leans on. Yes, if you're Batman you can read Javascript quickly and surmise the code's purpose.

But that's reading code - and it's quite different than "readable code" as dumb as that might sound. In the Ruby community, Rubyists will thrash themselves to make a chunk of code aesthetically pleasing as well as immediately "grokkable". This is the goal of the language, and I find it to be amazingly compelling.

C-based languages were written to be understood by machines, not humans, so there's a gap there. But let's get back to the point: is CoffeeScript more comprehendable than Javascript?

This is an excerpt from Ryan Florence's blog (it's beautifully laid out btw):

My takeaway from this is:

If you like C-based languages and you know Javascript deeply enough that glyphs make sense and you don't mind extra punctuation, use Javascript.But... Use CoffeeScript if you're averse to C structures and glyphs add noise to your code and you don't want extra code in your code for doing mundane stuff.

Remember, we're talking comprehension here, not syntax excitement. Which sentence sat happier in your brain? If we're going to get literal on comprehending editorial intent: it's a hard and fast rule that you start with a premise and build on it. That's writing 101 (and speaking 101 for that matter): lead with the punchline (or abstract) and then make your case.That's what CoffeeScript favors. But this is a small, silly example anyway.

Throw in the function() keywords a few times with some braces, parens and semi-colon eye-stabbery, then we can talk about "comprehension".

Overall I find this latter point a bit weak - yet it is a point: if you know/like/love C-structure, then Javascript is your buddy.

The rest of Ryan's post amounts to arm-waving about "what others might do" and how CoffeeScript allows you to shoot yourself in the foot if you point a gun at your foot and pull the trigger. Not terribly convincing stuff. Let's move on to Javascript.

You're Stuck If You Don't Know Javascript.

This is more my thought then Ryan's (and is common knowledge as well) - but I'll throw it in: if you don't know Javascript and you use CoffeeScript... you're in for trouble. This probably means you were weaned on Ruby/Python and you're hoping CoffeeScript will shield you.

This is a bad choice. If you don't understand the thrash-fest that is Javascript not defensively-written, you'll be in for a nightmare. It's true that CoffeeScript shields you from a lot of Javascript's warts - but you really need to understand those warts (and what you're avoiding) should you ever get backed into a corner.

Thinking logically - if you need to know Javascript in order to use CoffeeScript - why use CoffeeScript at all?

That, to me, is a very very compelling question. I can get over the code noise, and I can figure out the good patterns - so why mess with an interpretor? It seems like extra work for what amounts to syntactic sugar... is it really worth it?

Javascript Sucks.

I come from a C-language background (largely C#) so braces/punctuation don't scare me. I can scan Javascript quickly and understand most of what's happening - and I actually find it much more "legible" than CoffeeScript.

function()

I don't need to add much to this. I've pondered just how much I've written the word "function(..)" over the past years - and a thought occurred to me:

If I had a nickel for every time I wrote "function()", I could almost fill the void that is Avery's head.

(this is a derivation of a joke: "what would you rather have: 1 million dollars or Avery's head full of nickels" - it's a tough question).

I don't mind writing the word, I mind the repetition of it. Javascript is a functional language. As such your write... FUNCTIONS. Having a keyword called "function" seems a bit ridiculous. I'll get some hate for this - you can write me a little hate function and see how many function keywords you can use.function()

Moving on...

Aren't We Trying To Move Forward?

I was talking to a friend the other day and he just flat out said it:

I don't get why people like Javascript. It's a Neon and Acid Wash language

Again - this is a very smart person with way more experience then me reflecting on how Javascript is a language that's fascinating on some levels and, frankly, had its day. Many people love it, have come to terms with its existence - do we really need to go there again?

This opinion, while a tad blunt, isn't completely without merit. The language has flaws - flaws that are quite glaring and ones that will bite you by default. Global leaks, scoping issues, inconsistencies in comparisons and equality... this is all well known stuff.

When I started using Ruby (and Python... for a bit) it was such a fun exploration of what a modern, dynamic language could do. Learning those languages was joyous! Working with Javascript has been ... well a difficult walk down a painful memory lane for me (personally).

I find myself enjoying Node a lot - Mongo too. It's really fun to be learning and helping in a growing ecosystem. But... Javascript... it's so hard for me to look at the code I write and feel the same level of excitement and engagement that I did with Ruby.

Of course - this is my personal opinion and I know there are good parts (and yes I've read Crockford). My point here is that Javascript has a tarnished past. I know people are trying to spread Good Habits and that's exciting... but it also has its negative aspects.

There's a lot of elitism, snottiness, and overall pedantry in the hardcore Javascript crowd. Accidentally write a global variable and put your work out there for all to see... look out.

What To Do?

I'm on the fence here, but I feel compelled to make a choice. I'm leaning in the CoffeeScript direction because I enjoy the terser syntax and the Ruby aesthetic, but I also know that there will be times when it slows me down.

I'd love to hear your feedback, but please (as always) provide some reasons I can sink my teeth into and think about. Opinions are welcome too - just try to balance them on things other than links and quotes.I'll be moderating this thread heavily.