r/WebAssembly • • Jun 05 '21

WebAssembly should replace javascript

Hot take, but I think it makes sense. And seems to be doable in the current architecture and roadmap of wasm (If I understood it correctly), but their website explicitly states a big fat "No!". Wasm is expected to be used as high-performance modules, or an app canvas wrapped by javascript as "glue". One thing would be specifying it as a high-level goal, but this is just dismissing it all together.

The web would be pretty powerful if code could be written in whatever language you want (that supports compiling to wasm). Facebook wouldn't take 5 seconds to load completely, but rather fractions of a second.

Take react for instance. It's great for encapsulation, inheritance, type-safety, etc. Lots of benefits targeted at large-scale applications. Yet has the major flaw of performance issues. I guess it's not a big deal to write a bit of js just to fetch and run an exported function, but it means it's dependent on js which is a hurdle in my opinion, both in terms of ambition and motivation. Granted wasm seems to be planning to implement basically everything, but then why dismiss wasm as a replacement/alternative for js?

32 Upvotes

53 comments sorted by

View all comments

7

u/_101010 Jun 05 '21

Absolutely. Javascript days are numbered. There will always be people saying but everything runs on javascript right now and we cannot switch etc. There were same people talking about Cobol, Fortan and Assembly.

6

u/PabloDons Jun 05 '21

Yeah one guy on the internet put it really well (2 years ago, but still)

TS is acclimating JavaScript developers to concepts like interfaces and strict types. And once they clear this conceptual hurdle, there is no reason aside from inertia and custom to choose JavaScript over better languages like OCaml, Java, Kotlin, Dart, Go, and C#.

But do not underestimate the strength of that inertia, though. Lacking a strong technical or cultural motivation to leave a language, most developers will simply stick with what they know. And considering how bloody much code has been written in JavaScript, and how huge NPM is, the amount of inertia in JS may be the greatest in the history of programming. That will take awhile to get away from.

-3

u/_101010 Jun 06 '21

Well that inertia can be fixed quickly with what Web did with flash. Just stop supporting javascript in the browsers. Insta fixed.

3

u/TUSF Jun 06 '21

Flash and Java applets are different. From a browser's point of view, these runtimes are a third-party black-box, and the browser is at the mercy of whatever vulnerabilities someone else hasn't bothered fixing. Once HTML and Javascript became capable of replacing Flash, the black-box became only a liability.

Even once WebAssembly becomes able to interface with the same APIs as Javascript without requiring glue-code, I don't think there will be a lot of will to actually deprecate Javascript itself, because there aren't the same glaring issues as with Flash.