JS in Wonderland

In 1957, General Motors unleashed the greatest invention the world has ever known. Or at least that’s what a lot of people thought, until Cadillac Eldorados started plowing over pedestrians and crashing into other cars, highway medians, and large poles en masse. Cadillac’s new apparatus sounded too good to be true. It had a James Bond sex appeal. It was all anyone ever wanted from a vehicle since the first man looked to the sky, and saw the birds soaring, and thought: why not me?

Was it the flying car? No. It was better. Way better.

In 1957, Cadillac started building gloveboxes equipped with a minibar. One day later, the population of Detroit halved, and mortuary stocks soared, as everybody who was anybody went out taking shots and the wheel simultaneously, and looking over drunkenly to their friend and saying “follow that car!” and then, inevitably, running over several toddlers and Speed-Racing into a school bus shortly thereafter.

Some things that look good, sound good, and even smell good… some times they’re too good to be true. Sometimes they’ll send you out of control over a cliff. A glovebox minibar will do this. That little white rabbit did it to Alice. And syntactic sugar will do it to you, and here’s why:

Sexiness is subjective.

The trouble for me with CoffeeScript is: it’s so goddamn sexy. It cuts out the unnecessary, and it looks like English. Plus it’s concise. Every script is like a Hemingway short story. And can you spot that McCarthy punctuation? It’s beautiful!

1
2
3
4
foo (x) ->
  alert "Hello, #{x}!"

foo("World")

I mean, just look at it! It’s like Marilyn Monroe and James Dean had a baby. No squigglies. No parenthesis. No semicolons. No nothing. Move over if !ers,unless just stepped in the building. And did you hear about the rockets? The skinny ones? The fat ones? CoffeeScript gets rid of all the wastes. It leaves so much room for activities!

But wait a minute… is sexiness really the metric with which we want to be choosing the next language for our future billion-dollar application? Isn’t sexiness a little subjective anyhow? I mean, surely not everyone thinks CoffeeScript is sexy. And Mom’s been harping on me for years: “It’s the personality that counts.”

And she’s right. Justin Timberlake brought sexy back, but it’s already gone. It isn’t kool anymore anyway. You know what is? Readability.

You know what’s not readable in CoffeeScript, a function that takes a lambda as an argument. God forbid if one of the parameters is a dictionary. And what happens if you want to pass the result of function call directly to another function as a parameter?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
foo (x, y) ->
  x + y * x * y

bar (x) ->
  x + 42

foo 10, bar 20 # Is this a dictionary? A function call? WTF?

inject (x, y) ->
  x[y] = y

inject
  x: foo 10, bar 20,
  b: (n**2 for n in [0..5]).reduce (t, s) -> t + s,
  c: 3,
  "Z"

# ^ I don't know what anything is anywhere in there.

Sure, all of this can be fixed. But the problem is, like in Perl, it’s more common to abuse features that probably shouldn’t even exist in the first place–ahem list comprehension–than it is to use them elegantly. Assuming that code will be good is a dangerous assumption. Most code is bad. No matter how good you are, most people will think most of your code is bad. And in five years, they’ll think it’s even worse.

The fact of the matter here is: it’s a logical fallacy to say that anything that isn’t necessary is useless. Computers are far, far better at parsing code than my mortal self. Braces help me identify dictionaries in the same way that brackets tell me I’m accessing an index of an array. Parenthesis help me identify function calls. return helps me identify return statements… And even if they don’t help you, before you go off saving ten million keystrokes per second, maybe you oughta ask yourself: is it worth it? Is saving a couple of keystrokes worth confusing a percentage of your fellow developers? Is being clever really worth alienating someone that will inherit your code?

CoffeeScript accomplishes nothing.

The way marketing works is: you find what’s different about a product, and regardless of if it’s good or not, you sell it. The way developing a good programming language works is: you identify a problem in other languages, like concurrency, and you attempt to address it. Scala does this. Clojure does this. A million new languages do this. It’s arguable how good they are at it, but it’s pretty objective they’re designed with that intent.

But CoffeScript? Okay, it adds inheritance, but ECMA6 does that too… And isn’t composition the kool thing these days anyway? CoffeeScript’s only real selling point, if we’re being honest, is it’s syntax. And, I don’t think that’s the point you should be using to go all in on CoffeeScript for your next project. I don’t think you should follow that rabbit.

And besides, if C-style syntax is so bad you need to rewrite your entire codebase, if it’s so bad you don’t mind the vast majority of your dependencies being written in a different language, if it’s so bad you don’t mind it being a nightmare to use some of those dependencies, if it’s so bad you shake your finger at JavaScript and say, “I will not write you!”… maybe instead of installing the latest version of CoffeeScript and putting on your Fedora, what you really oughta be doing is asking yourself: why are the world’s most-used languages all C derivatives? That alone is proof of nothing, I’m aware. It doesn’t make C-style syntax the best. It doesn’t make it good. It doesn’t even make it not-bad. No, that’s subjective. But it does probably hint at that C-style syntax isn’t so bad it’s unusable. And if that’s the conclusion you come to, just be aware that the vast majority of the programming world is disagreeing everyday with commit numbers.

Accomplishing things is important.

So, wait, if I can’t use CoffeeScript because it’s different from JavaScript, what about TypeScript and Flow? What about Java? How’s that any different from C++? And what about Common Lisp? Don’t fuck with my Lisp, homie.

Well, Java gives you the JVM. And TypeScript allows you to catch compile time errors. These are the types of things that make me want or not want to use a language given a set of circumstances. Solving real problems gives me a reason to use a language. Sexiness is not a factor.

CoffeeScript gives me inheritance. But 1) don’t these same guys tell us to avoid that? And 2) that seems like something better suited for a library than an entirely new language. And 3) if you really just can’t live without extends being a keyword in your language, couldn’t you write a preprocessor that does that and only that?

You could. Except CoffeeScript isn’t about inheritance… even though that’s all it adds… What it’s really about is syntactical sugar. Can’t you hear Mom warning you about sugar as we speak? Can’t you hear her saying, “sugar is the devil”? Mom always knows best. Sugar is fun and sweet and we all love it, but it’s really not good for us. She knows. She always does.

So listen to Mom. No matter what a designer tells you, code isn’t beautiful. It’s data. Or at least that’s my opinion. Now if you’ll excuse me, I’ll go back to writing my ugly code.