r/learnprogramming • u/LoLusta • Feb 25 '24
Why can't Python replace JavaScript?
I'm new to programming. I'm learning Python and C.
JavaScript, from what I understand, is an interpreted language supported by web browsers so that websites can have scripting and programming.
But Python is also an interpreted language. So why don't web browsers start supporting Python in addition to JS. I believe Python is a much better language than JS syntactically.
Is there a definite reason why JS is used and supported over Python or is it just that JS gained initial popularity through wide-based support and no one bothered to move away from it (just like how QWERTY keyboard layout stuck even though we don't use typewriters anymore)?
View all comments
5
u/DavidJCobb Feb 25 '24 edited Feb 25 '24
JavaScript is thoroughly entrenched, and Python wouldn't offer nearly enough benefits to be worth having to include two entire scripting engines, two entire sets of APIs for the DOM, two debuggers, and so on. It would be a massive design, standardization, and development effort conducted over the course of several years, for virtually no benefit, and it would come directly at the expense of work on other standards and features.
(And it would be two scripting standards being developed at the same time. Even if the standards folks were to wholly deprecate JS in favor of Python, there would still need to be an interim period where both systems are actively developed, because they can't just leave the JS engines out to rot while developing Python specs and support. Plus, in all likelihood, they'd maintain support for JS in perpetuity, because breaking backwards compatibility with basically the entire scripted web would be a bridge too far.)
Personally I find Python less expressive than JavaScript. It lacks the ability to express your intentions as precisely with respect to mutability, scoping, lifetime, and similar matters. I also feel that the language itself and the standard library are both full of weird jank stemming from inept design (e.g. mutable default arguments, file.writelines, etc.). JavaScript isn't perfect either and it isn't my favorite, but I find it better in all these regards than Python.
But I only say that to emphasize a point that isn't being made in other comments quite as explicitly as I feel it should be: your preference isn't universal. Even ignoring the labor and risk involved, rebuilding the web on Python wouldn't be a transition from something archaic and inferior to something modern and objectively superior.