The paper contains 2189 words and is expected to last 7 minutes
Photo source: Unsplash
“There are only two languages in the world, those that people complain about and those that no one uses.”
— BjarneStroustrup, father of C++
Not everyone loves JavaScript.
Every now and then someone complains that JavaScript should be replaced by another language.
The reason: there are a lot of things about JavaScript that make no sense and should have been fixed long ago.
Because developers haven’t fixed these things, it’s easy to assume that JavaScript is a crappy language that can’t be fixed. In that case, it should be replaced with another language, preferably the one the joker likes best.
But is this really the case?
How did we get here?
Photo source: Unsplash
JavaScript is hardly a perfect language, because it does have some quirks. In just 10 days developers have designed JavaScript to look more like Java and have to live with the consequences.
But no language is perfect, and JavaScript has come a long way since ES6, and it continues to improve. It has evolved from a “toy language” for animating web pages to a programming language in the strictest sense, and JavaScript is now used in large and complex Web applications of all kinds.
JavaScript is so ubiquitous that it is by far the most used programming language in the world.
So why are some developers still clamoring to replace it?
Know the language
A lot of the jokes people make about JavaScript come from ignorance that they don’t know the language and don’t want to really put their heart into it.
The this keyword, stereotype inheritance, and lack of immutability are the top three sources of confusion in JavaScript. If the developer is used to another language, I can understand. Likewise, I can understand the confusion and anger this has caused.
But none of this is insurmountable. JavaScript is not that inscrutable if you want to learn it.
While it’s understandable for developers to think that swapping JavaScript for another language is a one-sideshow, it’s neither realistic nor a real solution.
The “Don’t break the Web” principle
The first design principle of JavaScript, HTML, and CSS is that new features will probably never break an existing site.
This essentially turns JavaScript into an add-only programming language: features can be added as long as they don’t break existing sites, and new features may never change or remove existing features.
This principle ensures that existing sites never crash, even if they were created decades ago, and Committee of Technical Experts no. 39 (TC39) goes to great pains to uphold it.
This is a good thing, but it does put a burden on JavaScript because features can only be added to it, not changed.
So, while confusing aspects of JavaScript can theoretically be fixed, such as the this keyword, they can break existing websites that were perfectly fine until they were fixed. Obviously this is unacceptable because it violates the “don’t break the Web” principle.
Using another language is not the answer
Photo source: Unsplash
It is theoretically possible to replace JavaScript with a new language, but it is possible that the technical and logical processing would be cumbersome and endless.
But the language also needs to follow the “don’t break the Web” principle, which basically turns the language into an add-on only language. It is probably predictable that enthusiasm for the language will decline, and that soon people will hear the same calls for its replacement.
This principle limits the way JavaScript can evolve, and will apply to any language that needs to follow it. This led to JavaScript today, which no language can replace without being bound by this principle.
JavaScript has maintained unprecedented backward compatibility over the past 20 + years, which is actually a huge achievement. JavaScript should be applauded for making the Web what it is today, not hated for it.
From scratch?
Photo source: Unsplash
Hopefully, developers have realized by now that it is not possible to completely replace JavaScript with another language. But if you really don’t want to learn JavaScript, you can do so through WebAssembly and a dozen other languages that compile into JavaScript.
I’m impressed with TypeScript because it adds statically typed features to JavaScript and PureScript, much like Haskell in browsers, for full-fledged functional programming.
But the extra editing step, as always, complicates learning, raising the question of whether it’s worth it. I recommend using TypeScript today because it is a superset of JavaScript and is very similar. TypeScript is also growing and has a large community.
It takes time to learn it, and you can use that time to learn JavaScript well. It’s not inscrutable, it’s not learnable, and once you master its oddities, it’s a very powerful and universal language. It’s not perfect, but it’s essential.
Then again, no language is perfect.
The choice is yours.
Leave a comment like follow
We share the dry goods of AI learning and development. Welcome to pay attention to the “core reading technology” of AI vertical we-media on the whole platform.
(Add wechat: DXSXBB, join readers’ circle and discuss the freshest artificial intelligence technology.)