WebAssembly's Name

November 19, 2020—Is it for the web? Is it assembly?

Here’s what WebAssembly has to say about itself:

WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications.

I’ve been learning WASM recently. I think I’m coming out of the Trough of Disillusionment. Let me explain why.

Hype: it’s not just web!

First, you need to understand that it isn’t limited to just the internet:

While WebAssembly is designed to run on the Web, it is also desirable for it to be able to execute well in other environments, including everything from minimal shells for testing to full-blown application environments e.g. on servers in datacenters, on IoT devices, or mobile/desktop apps. It may even be desirable to execute WebAssembly embedded within larger programs.

Right now with very little effort (thanks to two libraries alone) you can run WASM programs in all these languages:

  • C
  • C++
  • C#
  • Elixir
  • Go
  • Java
  • JavaScript (both inside and outside of a browser)
  • PHP
  • Postgres
  • Python
  • R
  • Ruby
  • Rust

And right now you can compile/convert all these languages and more into WASM:

  • C
  • C++
  • C#
  • Go
  • Rust
  • TypeScript

WASM is pretty flexible. It has provisions for interacting with the host environment but it isn’t overly opinionated about it. There’s a way to call host-provided functions (called “imports”). This has enabled the WebAssembly System Interface (WASI) spec, which is basically a pared-down set of POSIX functions.

Solomon Hykes, the co-founder of Docker, said this about WASM+WASI:

If WASM+WASI existed in 2008, we wouldn’t have needed to created (sic) Docker. That’s how important it is. Webassembly on the server is the future of computing. A standardized system interface was the missing link. Let’s hope WASI is up to the task!

Let me say that again: WASM (plus a spec for some imported functions) can do everything that Docker does.

These are all Good Things™. These kinds of things make me very excited as a programmer.

But something fishy is going on. Because it’s called Web Assembly.

Reality: it reeks of internet

These are some of the people paying for its development:

  • W3C
  • Google
  • Facebook
  • Apple
  • Microsoft

What do all of these big-name organizations have in common? The internet.

Now to be fair those aren’t the only organizations involved. But…

WASM is opinionated about function calls. It’s clear that function calls were designed in the context of C/C++ and JavaScript.

There is a lot of momentum pushing to additionally implement reference types. And not just reference types but even null. And not just that but they are pushing for garbage collection instructions. It’s clear from reading the designers’ comments online that the driving force behind these things is again JavaScript.

There is interest in expanding support so that more languages can be compiled to WASM, but it’s clear the goal is always to get those languages to run in a browser.

So which is it? Is it for the web or not?

Why don’t they just save garbage collection and reference graphs for a layer built on top of WASM? Because they want GC languages to be able to run in today’s internet browsers with minimal delay.

If I want to host WASM programs for purposes completely unrelated to the internet, how long do you think it’ll be before I’m forced to introduce internet concepts into the programs, or into the host? It won’t be long until WASM hosts will have to have garbage collection. Is garbage collection universal outside the internet? No. Is it universal to JavaScript? Yes.

Reality: it isn’t assembly

I don’t know of a single assembly language that:

  • Has garbage collection instructions
  • Has nullable reference types
  • Forces structured control flow

Now I might be wrong. There might be other “assembly” languages with those things. But those things certainly don’t sound like “common hardware capabilities”.

WebAssembly aims to execute at native speed by taking advantage of common hardware capabilities available on a wide range of platforms.

So why did they both plan those things and call it Web Assembly?

The point

Coming out of the Trough of Disillusionment implies I’ve crested the Peak of Inflated Expectations. So what was I expecting?

I was expecting the One Language to Rule Them All. I was expecting a universal assembly language.

WASM just isn’t what I was hoping for.

Is it good for running programs in today’s internet browsers? Sure. But I think it is being influenced too much by today’s internet technologies. And we all know how fast the internet changes.

So I’d stick to the web for WebAssembly.