The State Of JavaScript: JavaScript Flavors
Sacha Greif
3729

“One thing that distinguishes JavaScript from other programming languages is that JavaScript isn’t just one language:”

False. Every popular programming language is really multiple languages. But the existence of Coffeescript, Typescript, etc is not the fundamental cause of the fact that JS isn’t just one lang, its something much deeper.

A language is a mapping between syntax and semantics. To the extent that its a one to one mapping, you have one coherent language. To the extent that its not, you don’t. So if a language has synonyms, it is not a one to one mapping. If a language has multiple meanings for a word/phrase its not even a language, its a train wreck. (English is a “good” example here!)

The most important features to compare modern programming languages on is how they deal with two issues: function/method calls and object systems.

JS 5 has two function calling syntaxes, prefix and infix. So

foo(a, b) and a + b are examples.

Having 2 syntaxes for the same thing is bad, really bad. Having 2 syntaxes means you have to know them both, because you have to read other people’s code and you can’t do everything you need in one syntax. Having to know both means you not only have to know the two independent things, you have to know how they interact with each other. Infix is so bad that you have to know complex rules on how it interacts with itself.

2 + 3 * 4 is an example. What the heck does that mean?

What about 2 / 3 % 4 ? Having to know precidence rules is just stupid lang design. But ES6 introduceds arrow functions. Oh great, now I have to learn a 3rd synonym for function calling, Or maybe its not quite a synonym. Yuck. things aren’t all quite roses with prefix either, starting with definitions. function (){ x} returns the new function .

function foo(){x} doesn’t. Bad idea to have this inconsistency.

And what language is “function foo (){}” in? Its not infix but its not prefix.

Its its own ideosyncratic lang. It could be:

def(“foo”, [a, b], x) for instance but you need to have some extensions to “not eval a and b” . Those extensions are useful in many other cases, but JS non-design doesn’t understand this.

JS is not alone in this arena of bad design. In Ruby I counted 6 different ways to make a function call before I gave up. For your own programming style, you can avoid some of these synonyms, but if you want to read other people’s code, you can’t.

On the object side, JS is even worse. Old JS was said to have a prototype object system. Prototype object systems done well are a great idea, much better than class-instance because they’re simpler yet more funtional. Done badly, like JS, they’re such a mess that everyone and their brother creates a new “style” of using them such that its just an unholy disaster. Because of this, the ES6 group decided to introduce a class-instance object system because nobody could figure out how to use JS5's “prototype” object system. This is like: rather than putting out the fire in my house, I’ll just build a new house, but I’ll still use the old house for the bathroom.

The reason we have coffeescript, typescript, etc. is because of this chaos in the fundamental language. When something’s bad, people want to improve it. Now we’ll always want to EXTEND any decent programming language with new capabilities. This is the job of LIBRARIES but jquery, css, coffeescript, etc are not merely libraries. They introduce new syntaxes, new function calling pardymes, and often new object systems. Heck typescript attempts to make a whole new TYPE system. That’s not a library, that’s core to what a language is. If JS had a decent type system to begin with, there would be no need for a Typescript.

Now the JS community as of late made an important choice. We’re going to keep JS backwards compatible. I understand this choice, I respect it. It has many good qualities. I write JS code and I don’t want old code breaking with every new version of JS. But this means JS can NEVER be a good language (go back to my very definition of language). So we will always have the reacts, the meteors, the angulars, the typescripts, the synonyms, the 17 object systems. But all the other popular languages: Python Ruby, C, C++, C#, Swift, Java have severe problems too. We might say that in some sense JS is good in that its flexible enough to allow the reacts and the typescripts whereas those kinds of extensions couldn’t be done in most other langs. But then some of those other langs don’t need them. You see infix and prefix in every popular lang. You see class-instance object systems in all other popular langs. We are (humanity) and, according to all trends I see, in horrible shape w.r.t lang design, even though ES6 has a lot of great new features which I use, and ES7 has more that can’t come soon enough.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.