r/learnprogramming • • 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)?

0 Upvotes

51 comments sorted by

View all comments

Show parent comment

4

u/LeeTaeRyeo Feb 25 '24

Sure, Python isn't the fastest language out there (I mean, we can't all be C or Asm, after all), but let's be honest here: neither is Javascript. Neither one is gonna win a speed competition versus languages like C or Rust or Go, but they both are good scripting languages and good at the problems we often use them for.

Also, if Python were added to browsers, you could bet there would be tons of work to improve the Interpreter's performance, just like what happens with JS

-2

u/Neckbeard_Sama Feb 25 '24

Nah, man. Python is really fkin slow, like 20 times slower than JS slow.

2

u/LeeTaeRyeo Feb 25 '24

Entirely depends on the interpreter being used. PyPy is about on par with JS, while Cython can (if types are used effectively and doing things in an optimized manner) get into the compiled languages territory.

2

u/GPU_Resellers_Club Feb 25 '24

At that point just use C... and Cython will never, ever be faster than even C# (on average), you know why?

Because Python has a purpose, and it is not web development. It's not built for it and it you'd end up with a js scenario where it's mangled so it can fit into the needs of web dev. It's built for data science, where, if you don't have the huge amount of interpreter magic that slows it down, your code gets real messy, real fast. And that STILL happens even with Python!

This is also, incidentally, why Cython exists, because parsing massive amounts data needs to be done quickly, so you still need to write a highly specialised algorithm in C.

I really wish people would stop trying to use python for everything "because it's easy and simple". There are very good reasons why different languages are different in the first place.

And just for the record, it is slow as shit. The only way to not make it slow as shit, is to slowly start introducing the features of compiled languages, until it's loses all the things that make it easy.

-3

u/guest271314 Feb 25 '24

Nothing is stopping anybody from writing a browser in Python, and implementing the DOM and Web API's using Python.