logoalt Hacker News

pizlonatortoday at 4:28 PM3 repliesview on HN

It's simple.

JavaScript is the right abstraction for running untrusted apps in a browser.

WebAssembly is the wrong abstraction for running untrusted apps in a browser.

Browser engines evolve independently of one another, and the same web app must be able to run in many versions of the same browser and also in different browsers. Dynamic typing is ideal for this. JavaScript has dynamic typing.

Browser engines deal in objects. Each part of the web page is an object. JavaScript is object oriented.

WebAssembly is statically typed and its most fundamental abstraction is linear memory. It's a poor fit for the web.

Sure, modern WebAssembly has GC'd objects, but that breaks WebAssembly's main feature: the ability to have native compilers target it.

I think WebAssembly is doomed to be a second-class citizen on the web indefinitely.


Replies

eqriontoday at 4:41 PM

I'm not sure I follow this.

> WebAssembly is the wrong abstraction for running untrusted apps in a browser

WebAssembly is a better fit for a platform running untrusted apps than JS. WebAssembly has a sandbox and was designed for untrusted code. It's almost impossible to statically reason about JS code, and so browsers need a ton of error prone dynamic security infrastructure to protect themselves from guest JS code.

> Browser engines evolve independently of one another, and the same web app must be able to run in many versions of the same browser and also in different browsers. Dynamic typing is ideal for this. JavaScript has dynamic typing.

There are dynamic languages, like JS/Python that can compile to wasm. Also I don't see how dynamic typing is required to have API evolution and compt. Plenty of platforms have static typed languages and evolve their API's in backwards compatible ways.

> Browser engines deal in objects. Each part of the web page is an object. JavaScript is object oriented

The first major language for WebAssembly was C++, which is object oriented.

To be fair, there are a lot of challenges to making WebAssembly first class on the Web. I just don't think these issues get to the heart of the problem.

show 2 replies
saghmtoday at 6:05 PM

I'm not convinced JavaScript is a great abstraction for the browser as much as we've forced the web into a shape that fits JavaScript because of a lack of viable alternatives. I'd argue that the popularity of TypeScript implies that dynamic typing is not a universal ideal. Browser engines deal in objects because they're currently all built on top of JavaScript only; that doesn't demonstrate anything fundamental about the web that implies object oriented is the only reasonable representation.

If it gets stuck as a second-class citizen like you're predicting, it sounds a lot more like it's due to inflexibility to consider alternatives than anything objectively better about JavaScript.

flohofwoetoday at 4:34 PM

That's just like your opinion man ;)

(I'm not a fan of the WASM component model either, but your generalized points are mostly just wrong)

show 1 reply