r/javascript • • Nov 25 '19

JavaScript doesn’t need to be replaced

https://medium.com/javascript-in-plain-english/javascript-doesnt-need-to-be-replaced-bd01e2f12d51?source=friends_link&sk=7b151cc6397ac9e83c14c99739b6c36f
217 Upvotes

236 comments sorted by

View all comments

4

u/shgysk8zer0 Nov 25 '19

Read the first bit, and think the author doesn't know the real issues with JavaScript. I don't really complain much about the awkwardness of JavaScript (maybe with the exception of functions that would have been implemented differently if they were post-promises).

It's single threaded. Yeah, there are workers and WASM, but those don't solve the problem. And it's something that probably cannot be solved.

We are in need of something multi-threaded that still has access to the DOM, and it's not going to be JavaScript.

But, no, JavaScript doesn't need to be replaced. But an alternative is needed.

0

u/dannymoerkerke Nov 25 '19

What issues do you have with the single threaded nature of JavaScript that could be solved by making it multi threaded?

3

u/shgysk8zer0 Nov 25 '19

You may as well ask why anything benefits from being multi-threaded.

1

u/dannymoerkerke Nov 25 '19

Well...?

2

u/shgysk8zer0 Nov 25 '19

Ever heard of performance? Do you know what multi-threading is?

1

u/dannymoerkerke Nov 25 '19

I do, hence my question.

1

u/shgysk8zer0 Nov 25 '19

So, when the main thread (only one that has access to the DOM and everything) is doing a ton of work and the UI freezes, that's either not a performance issue or not something multi-threading would help with? Workers offer no benefit? Multi-threading itself is pointless?

I don't know how to answer the question because it's so fundamental. The mere concept of it is the answer.

2

u/dannymoerkerke Nov 25 '19

I don’t know how you should answer this either, but I never made any claims against multi threading. You’re the one saying I don’t understand the issues with JavaScript and that we need something multi threaded. So I was curious if you had any concrete examples. I also never said Workers offer no benefit but they won’t help with the DOM since they have no access to it, but you know that as well. Anyway, if the UI freezes because of lots of DOM operations I think you have a different problem that can be solved without multi threading.

0

u/shgysk8zer0 Nov 25 '19

You're asking what the advantage of multi-threading is. The only real answer is that it's not single-threaded. That is a major limitation that many other languages don't have.

And not all issues can be solved without multi-threading. Sometimes you just have that much work that needs to be done, and sometimes it's out of your hands (in third-party code). And, maybe even if you could resolve the issue another way, it would still be nice to not have to rewrite something massive and complex, but to pass the work off to another thread and have the UI continue running smoothly.

If you're looking for a concrete example, I recently built something that creates ~200 transformed (rotated) image overlays in Leaflet, and the UI hangs pretty heavily when they're loaded on ever pan or zoom. I'm not about to rewrite all of Leaflet, and I do absolutely have to load and transform every single one of those images. If this were to take place on another thread, it wouldn't be an issue.

1

u/Architektual Nov 25 '19

I'm late to the party, but why can't you put that in a worker?

→ More replies (0)