Wednesday, December 28, 2011

JavaScript Is Not A Language



Recently people presented arguments for and against using CoffeeScript. I felt the argument against was pointless and obviously wrong, but I couldn't figure out why, and I thought the counterargument for was kind of toothless and irrelevant. I've figured out the real issue.

The real argument for CoffeeScript is that JavaScript is not really a language.

Years ago I read something which explained, in my opinion, why Lisp has never achieved the mainstream adoption its passionate advocates believe it deserves. Lisp projects experience a degree of balkanization because everything is left wide open; you can use more than one object-oriented paradigm (potentially even at the same time), you write your own this, you write your own that, you write your own everything.

At Canada on Rails in 2006, somebody asked DHH why Rails didn't have a to-do list generator, and he said it was the wrong level of abstraction; to-do lists are always application-specific enough that any generator worth a damn would be as complicated as Rails itself, and probably as many lines of code. It's not something you can solve at that level of generality.

Lisp fails to recognize this, and rather than being a language, it is an abstract syntax tree manipulation system. An abstract syntax tree manipulation system is something every language needs and is built on, but it is not a language, any more than a skeleton is a person. Programmers who say Lisp is better than any other programming language are really saying that they prefer manipulating the abstract syntax tree directly vs. using somebody else's user interface for the same task, which is all a programming language ultimately is.

JavaScript is a Lisp with hideous syntax. Not surprisingly, it sees similar balkanization. Consider writing modular code. Do you use CommonJS, require.js, or something else? The question is idiotic; it should be answered at the language level. Do you choose which modular code-sharing system to support when you sit down to write your module? If you have three different solutions for writing modular code, you can't write modular code.



I use CoffeeScript for the same reason I use Ruby. Manipulating the abstract syntax tree directly is way more fun, but insufficiently pragmatic.




Update: I realize this blog post gets a bit idiotic with regard to technical details, and I've seen some Lisp fanatics ranting about what appear to be many entirely legitimate objections to the "JavaScript is a Lisp" meme, but I think my basic point here is pretty much dead on. Writing CoffeeScript just feels like using a language in a way that writing JavaScript just doesn't -- and I was doing drag-and-drop widgets before even Prototype existed.