49

JavaScript doesn’t need to be replaced - JavaScript in Plain English - Medium

 4 years ago
source link: https://medium.com/javascript-in-plain-english/javascript-doesnt-need-to-be-replaced-bd01e2f12d51?source=friends_link&%3Bsk=7b151cc6397ac9e83c14c99739b6c36f
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

JavaScript doesn’t need to be replaced

Other languages will face the same issues.

Image for post
Image for post

Photo by Jose Fontano on Unsplash

“There are only two kinds of languages: the ones people complain about and the ones nobody uses.”

Bjarne Stroustrup — Creator of C++

Every now and then someone will argue that JavaScript needs to be replaced by some other language. The reasons for this are always that JavaScript has too many quirks that should have been fixed a long time ago.

But since these haven’t been fixed it apparently means that JavaScript is a crappy language that’s simply cannot be fixed. And so it needs to be replaced, preferably by the complainer’s favorite language.

But does it really?

How did we get here?

I’ll be the last person to say that JavaScript is the perfect language. It has strange quirks. It was designed in ten days and then made to look more like Java. Unfortunately that’s the legacy we’ll have to live with.

But no language is perfect and JavaScript has improved tremendously since ES6 and continues to do so. It has evolved from a “toy language” only used to animate things on web pages to a serious programming language used today to run large, complex web applications.

JavaScript is now literally everywhere and the world’s most used programming language.

So why do some developers still cry for its replacement?

Know your language

A lot of criticism towards JavaScript comes from ignorance, not knowing the language and the unwillingness to truly learn it.

The this keyword, prototypal inheritance and the lack of immutability are three sources of confusion in JavaScript. I get it if you’re used to a language that behaves differently. I understand the confusion and perhaps irritation caused by this.

But these are not insurmountable obstacles. It’s really not rocket science to really learn how JavaScript works, if you’re willing to do it.

It’s understandable that developers argue for another language to replace JavaScript and fix the issues once and for all, but this is both unrealistic and not a real solution.

Don’t break the web

The number one design principle for JavaScript, as well as HTML and CSS, is that new features may never break existing websites.

Essentially, this turns JavaScript into an addition only programming language: features may be added as long as they don’t break existing websites but existing features may never be changed or removed.

This principle guarantees that existing websites will never break, even if they were built decades ago and the TC39 committee goes to great lengths to ensure this principle is upheld.

This is a good thing, but it does place the burden on JavaScript that features can only be added to it and not changed.

So while confusing aspects of JavaScript like the this keyword for example can in theory be fixed, this may break existing websites that worked perfectly before this change was made. And this is simply not acceptable since it violates the “don’t break the web” principle.

Another language is not a solution

In theory a new language could be implemented to replace JavaScript. I guess it would be a technical and logistic nightmare that would take an eternity, but it’s not impossible.

But that language would also need to adhere to the “don’t break the web” principle, which basically turns it to an addition only language as well. I guess you can already predict how the enthusiasm for this language would decline and soon we would hear the same cries to replace this language as well.

The constraints that are put on JavaScript by this principle limit the ways in which it can evolve and will apply to any language that tries to adhere to it. This shaped JavaScript into what it is today and there’s no way for a language that would replace it to escape this fate.

It’s actually a tremendous accomplishment that JavaScript has maintained unprecedented backwards compatibility for well over two decades. This has played a great role in the evolution of the web into what it is today and JavaScript should be applauded for that, not hated.

A clean slate?

I hope you realize by now that another language replacing JavaScript completely is highly unlikely. But if you really don’t want to learn JavaScript properly, there’s hope for you in the form of WebAssembly and a dozen other languages that compile to JavaScript.

I continue to be impressed by TypeScript which adds static typing to JavaScript and PureScript, which is basically Haskell in the browser and that enables you to do full-blown functional programming.

But as always, an extra compilation step adds complexity and the question is if that’s worth it. At the moment I would advice to go with TypeScript since it’s a superset of JavaScript and therefore it’s very similar. It’s also actively developed and has a large community.

You will need to spend time to learn it. Time you could also use to properly learn JavaScript. It’s not rocket science and once you are aware of it’s quirks you will see it’s an incredibly powerful and versatile language.

It’s not perfect, but then again no language is.

The choice is yours.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK