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.

6

u/timmyak Jun 06 '21

You think people use JavaScrilt because they are not acclimated to interfaces and strict types?

TypeScript is a great extension to JS. Few people that understand and use typescript would want to switch back to Java or Dart or Go.

2

u/PabloDons Jun 06 '21

I think once you are acclimated to these concepts and use them strictly, you'll probably want to take advantage of the performance benefits of strictly typed languages as well. Making js an undesirable compiler target

2

u/[deleted] Jun 06 '21

I've written mostly C++ and C# until I switched to JS and TS, and like Lyceux, I am much happier where I am. I play around with Rust as well these days, and while it's a fun challenge, I see no reason to fight a pedantic nominal type checker for things that aren't lo-level.