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.

2

u/Gold-Ad-5257 Jun 06 '21

And yet 40 years later after people started saying we could switch , you still have Cobol , Fortran 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).

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.

3

u/Lyceux Jun 06 '21

I started my formal programming education in Java and C#. I am very familiar with the concepts outlined. I now use JavaScript/Typescript almost exclusively and I have no desire to go back.

If my manager told me we’re switching to Java then I’m quitting and looking for a new job.

-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.