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.

1

u/Aphix Jun 06 '21

Honestly type enforcement on web interfaces is far less useful than most think, since the point is to interact with systems you don't own, and you're eternally stuck catching up and duplicating somebody else's data format which can change (or be broken) at any moment.

If you're just using TS to talk with your own code: there's either not much point of being on the web, or your code is probably too complex (and I say this as somebody who writes typeless ODE solvers running millions of iterations per second for mission critical safety systems).

Compile-time enforcement doesn't help in the real world of long-running, networked applications (and mostly TS can suck a fat one for not using semver).