I’m convinced WebAssembly is the next big thing, and it stretches beyond the Web. Here’s my experience learning the basics with the help of Rust.
“If you want to understand something, write about it”. So I decided to follow the famous advice and tell a short story about my foray into the WebAssembly land.
WebAssembly (a.k.a. Wasm) is an open standard that includes specifications for bytecode, its text representation and a secure host environment that would execute the code. The initial aim was to run C code on the web, but eventually, a range of compilers and runtimes was developed. So now we can run WebAssembly without a web browser or JavaScript.
It’s not the first attempt to create a cross-platform runtime. How is WebAssembly different from the previous “write once, run anywhere” technologies?
Now that I wrote this it looks strange that it is the four “have nots” rather than “haves”. I think it’s an important thing about WebAssembly: it’s not Java. It’s so simple, open and universal that it can run anywhere.
I can’t count how many times I saw the phrase that WebAssembly isn’t designed to replace JavaScript, but rather to complement it. Well, let’s be honest: I did my time as a web developer and I’m not a fan of JS. When I’m looking at WebAssembly, what I actually think is “Can it replace JavaScript?”. Many people focus on performance, and it is important, but what if I just don’t want to write JavaScript anymore? When will its unnatural monopoly come to an end?
WebAssembly may be the answer to that question.
I wanted to start from a relatively low level — no complex frameworks, no tooling. I like to know how things work before I use a high-level framework. At the same time, I wasn’t determined enough to write WebAssembly by hand. And didn’t want to write any C code either.
Fortunately, we have Rust programming language. Rust is characterized by two main things: it doesn’t let you mismanage the memory (by applying its novel ownership system), and it doesn’t use garbage collection — which means there’s almost no runtime. These traits make it an ideal language to be compiled to bytecode and run on a light virtual machine.
Such as WebAssembly.
For our little experiment we’ll need to install a few bits and pieces:
wasm-gc
optimiser: cargo install wasm-gc
cargo install wasm-pack
Miniserve
, a simple web server: cargo install miniserve
#webassembly #rust #web-development #javascript #developer