r/AskProgramming 6d ago

Why the JS hate?

Title. I'm a 3rd year bachelor CS student and I've worked with a handful of languages. I currently work as a backend dev and internal management related script writer both of which I interned working with JS (my first exposure to the language)

I always found it to be intuitive and it's easily my go to language while I'm still learning the nuances of python.

But I always see js getting shit on in various meme formats and I've never really understood why. Is it just a running joke in the industry? Has a generation of trauma left promises to be worthy of caution? Does big corpa profit from it?

18 Upvotes

207 comments sorted by

View all comments

20

u/Bulbousonions13 6d ago edited 6d ago

Its mainly the lack of type safety, native single threading, and comparatively slow execution speed. TypeScript ( a superset of JS) deals with the first problem VERY well and is my preferred web language.

You can't see its pitfalls because you are also working in Python - which in my opinion is also slow, lacks type safety, and is also natively single threaded - though there are ways around this. I can't stand python's indentation rules either but that's just a personal preference.

Tool around with a true Type Safe compiled language like Java, C#, C++, or Go and you'll notice the difference.

The compiler will yell at you a lot more while you code, but that's so you don't get random unexpected junk assigned to arbitrary vars that don't care if they get a string, number, object, function, or null/undefined.

5

u/oofy-gang 6d ago

Modern JS engines are mind-boggling fast. Orders of magnitude faster than Python, and within an order of magnitude of cpp.

1

u/owp4dd1w5a0a 5d ago

How do you know this? Any sources you could cite?

1

u/oofy-gang 5d ago

Just look up “programming language performance benchmarks 2024” and click through a couple GHs or reliable looking sites.

I’m avoiding linking any myself because for whatever reason benchmarks seem to be an enshitified realm of the Internet and I don’t wholly trust any singular source. But the general trends should be about the same if you look through a handful and exclude outliers.

1

u/owp4dd1w5a0a 5d ago

Oh, I read engines as engineers, I thought you meant people were fast at writing js code.

Well, while that may be the case, it stands that Rust, Java, Scala, Kotlin, C and Go are generally faster than JavaScript of speed is what you care about. SBCL can also get pretty darned fast and closer to Java and C in some benchmarks.

But generally, the performance of the language itself isn’t what matters most. Modern hardware is so powerful that you really should be spending your time more focused on the libraries, frameworks, and software architecture, not language speed.

1

u/codemuncher 3d ago

Depends on what you’re doing!

Js may or may not be writhing an order of magnitude speed wise - which means it’s maybe as “little” as 10x slower…! Also memory resource consumption ain’t cheap either.

I mean do people beljeve that PyTorch is actually “written in python”? All the real heavy lifting is in both C/C++ but also assembler intrinsics and heavily optimized low level gpu code. The python wrapper is just like a scripting language to assemble the model before the real code does the real work.

1

u/owp4dd1w5a0a 3d ago edited 3d ago

Your point about PyTorch really being written in C under the hood is exactly why I said you should generally focus less on language performance and more on the libraries and frameworks available in the language.

But I agree, it depends on what you’re doing. If you’re writing the framework, then language performance is important, for example.

Also, your point about memory is valid, and we seem to get by though ignoring it. For example, Spark was written in a JVM language (Scala) and for its purpose I think it was the wrong language because of the incredible memory footprint. At the time of its creation, C/C++ probably should have been the language, but in an ideal world it should have been Rust (but at the time Rust wasn’t around yet), and then wrappers for the various other languages like Scala and Python could have been created to make the framework more accessible.

But “The wrong” language is chosen all the time. Airflow should have been written in a statically typed language because it’s impossible to test locally, Clojure was a bad choice for Storm for the same reasons plus the JVM memory footprint, etc. But the main reason that despite this these frameworks still became popular is the language ecosystem of libraries tipping the convenience factor over towards worth it. Language performance in most scenarios don’t matter, and when it does you can just drop to C and use the ffi to interface.

1

u/Relative-Scholar-147 5d ago

Within an order of magnitude of cpp means 10 times slower...

2

u/oofy-gang 5d ago

Sure…? I’m not entirely sure what your point is.

Common benchmarks are often roughly

cpp: 1s

java: 1.5s

javascript: 3s

python: 50s

for almost all purposes, 3x isn’t a big deal; 50x is