Grumbling about JavaScript

Must... resist... killing... JavaScript

Must… resist… killing… JavaScript

This article describes why JavaScript is crap and its community is dumb, from an object-oriented point of view. It names alternatives and shows why they are problematic. It reveals that waiting for later versions is an option.

Today I don’t want to invest too much time into writing my daily blog post. So I have to come up with a trivial topic: What’s bad about JavaScript?

Why bothering with JavaScript at all?

Well … when developing web-front-ends (i.e. websites) there is no other alternative. JavaScript is the only language supported by all major browsers.

There are tons of attempts to overcome the inabilities of JavaScript and still run dynamic websites. Every big company and organisation comes up with at least one of those attempts. Some provide languages for their own embedded web-players, like Flash, Java or Unity. Others provide languages which cross-compile to JavaScript, like TypeScript, CoffeeScript, Dart and GWT, to only name a few. And there are attempts to improve the language inside the language itself, e.g. MDN, JSDocs and Closure Tools.

The web-players have the big disadvantage, that they require the user to install something additional to their browser. Thus they don’t reach all internet users, but only those, willing to invest the extra effort.

The cross-compiling approach still compiles to JavaScript. So they just add a new layer of abstraction, to hide the ugliness of JavaScript. When developing with one of those, sooner or later you’ll have to bother with JavaScript again.

The approaches to improve stuff inside of JavaScript itself are too artificial. They violate the Linguistic Modular Units Principle which states that

Modules must correspond to syntactic units in the language used. – Bertrand Meyer: Object Oriented Software Construction

So if you want to reach the whole web, you have to bother with JavaScript.

Whats wrong with JavaScript people?

Because of its monopoly JavaScript has become the most used language.

Because of its monopoly JavaScript has become the most used language. (Source: redmonk.com)

So we have a language that exists and evolves for almost 20 years now. Because of its monopoly it has grown to the most used language on GitHub. And all bigger organizations come up with their own workarounds to do proper object-oriented front end development.

And yet the language is missing many of the most basic concepts of object orientation. Many JavaScript-only developers don’t even know those concepts anymore, after JavaScript brainwashed them for 20 years. They even build up back-end solutions (node.js) on this mess, because they don’t know any better.

I guess the main reason for this phenomenon is that is JavaScript built upon the democratic compromises that competing companies – like Google, Apple & Microsoft – make.

Missing Concepts

Often people argue that JavaScript is only a scripting language and that most of the concepts below can also be reconstructed with cumbersome workarounds in JavaScript.

But due to the growing amount of web users, there is a trend to so-called fat clients. It means that the front-end becomes big and heavy-weight. So how is a simple scripting language the answer to that? Instead, a language that fails fast and scales properly is required.

Reconstructing object-oriented concepts violates the Linguistic Modular Units Principle again (see above).

No Classification

I mean, wtf? Prototypes instead of classes? I need a whole article to explain all reasons why this is a dumb idea! So just a few words.

First of all prototypes are a special case of initializing objects in object orientation, but not the other way around.

Secondly you can not do proper design on instance-level. You’d have to argue about each single possible case like: “If costumer A…”, “If customers A and B …”, “If customers A, B and C…” etc. Instead you want to argue one abstraction level higher and say something like “If a Customer”. So in your mind you classify the 3 objects A, B and C to be similar. They all belong to the class Customer. Then after you made that abstraction in your mind, you need to throw it away and implement the three objects A, B, C, etc. because JS isn’t capable of classes.

No explicit type system

Having no explicit typing (i.e. you don’t declare a variable has to be a string) has some advances: It’s good for quick and dirty prototyping and easy for beginners to learn.

In a commercial environment however it’s preferable to find bugs before you deliver your software. So you need the errors to occur early: in the developing phase or even before (fail fast again). A proper type system is a way to accomplish that for some kinds of errors. In JavaScript you just have to hope for the best 😐

No visibility constraints

One fundamental concept of object orientation and modularity is to restrict whats visible. It’s known as Encapsulation or Information hiding. This concept is so fundamental, that I don’t want to explain it’s importance in this shot article.

Not restraining the visibility –  like you do in JavaScript, because you can’t – is a bad practice. There are many names for it: Indecent Exposure, Inappropriate Intimacy, strong coupling, to only name a few.

And many more

The language has many more problems, mostly resulting from the missing class system. I won’t explain them all here, but some of them are: No Inheritance, No Interfaces, No Modules, No proper editors (capable of code completion, code navigation, refactoring, etc.).

But there is hope

In ECMAScript 6, the upcoming version of the language JavaScript core, they finally managed it to introduce the first object-oriented concepts. They’re not introducing all the concepts for some reason, but among the introduced concepts are: Classes, Interfaces, Inheritance, Modules, Anonymous Functions, Generics and a Static Type System. That sounds like a step into the right direction.

Maybe after all the JavaScript people aren’t as dumb as expected. It just took them a little longer, due to their democratic nature.

After all the post wasn’t as trivial as expected because there is so much bad about JavaScript.

Waiting for the shitstorm of brainwashed JavaScript people, telling me that anything can be done in JavaScript now,

Waog

Edit:

Almost one year after writing this post, I found this on twitter. Problems are still the same:

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s