Why is Rust interesting for WebDevelopers?

One (combined) word: WebAssembly!

🧵🔽
1️⃣ Why Is This Interesting At All?

WebAssembly has the chance to become for JavaScript what C, C++, and Fortran are for Python.

JavaScript has its limitations, as well as Python does. Python solves this by having an awesome native interface that allows easy integration ...
... of low-level libraries. JavaScript has C/C++ in Node. But in the browser? Sure, floating-point arithmetics can well be done with the help of WebGL and shader language, but there is no common low-level target for all of JavaScript.
This is where WebAssembly comes in. It could solve many of the problems one might run into when doing some heavy number crunching or string manipulation on a huge scale.

When you reach a hot path that you cannot or don't want to optimize any further, but which still ...
... isn't fast enough, you could swap this path out for an implementation in WebAssembly, and (hypothetically) gain a lot of performance.

This comes at the cost of switching languages, but perhaps preserves the benefit of readable code. The choice is up to you.
2️⃣ Okay, What Is WebAssembly?

WebAssembly (short WASM) is a byte code that can be processed and executed by a runtime. This runtime is built into most modern browsers and is also a part of Node.

It is a language that can be read by humans but is optimized for being ...
... executed by runtimes and is especially meant as a compile target. You won't write WebAssembly yourself, although you could. You usually write code in a language you are comfortable with and then compile it down to WASM.
3️⃣ What Has Rust To Do With It?

Glad you ask! WASM is a first-class citizen of Rust. The tooling is mature and plentiful and the resulting binary code is actually one of the fastest and most efficient put out by any compiler currently on the market.
Take a look at the code below. That's everything. And yes, it does exactly what you might expect it to do!

When you compile this with the proper tooling you get:

- A WASM file containing the compiled code
- A JS file as an importable module
- A *.d.ts file for TS types
You could even pack this into an npm module and then import it into your own project. You won't have to deal with much integration work, only with the code you write. That's the awesome thing about Rust and its WASM tooling. After compilation, it's usable directly.
4️⃣ How To Get Started?

Rust has a book for everything. No difference for WASM.

The Rust WASM book is a great first entry into Rust and WebAsembly in combination with web development.

https://rustwasm.github.io/docs/book/ 
5️⃣ Anything Else I Can Profit From?

Yes. WebAssembly is currently on its way to become a universal bytecode not only for web development but also for many more things.

There is a universal WASM runtime now, you can create smart contracts with it (Elrond), you can ...
... run it directly in Kubernetes (Krustlet), and so on.

There are even more experiments going on right now which might lead to WebAssembly really gaining speed and traction.

Knowing a language that easily compiles down to it could be pretty beneficial in the long run!
You can follow @oliverjumpertz.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.