Web Programming Languages: How WebAssembly Will Change the Way You Build Web Applications

What if you could write software once and make it work on all phones and computers?

Although this dream is still a long way off, steps are underway to transform the web browser into a universal computing platform capable of running even the most demanding applications.

WebAssembly, a binary instruction format that allows browsers to run software 10% to 800% faster than is typically possible with JavaScript, helps make that vision a reality.

The performance gains made possible by WebAssembly could one day see the heaviest of desktop software running in the web browser. WebAssembly is already being used to run the traditionally very demanding AutoCad software as a proof-of-concept demonstration.

“My dream is for every platform to become the web platform,” said Ashley Williams, systems engineer at Cloudflare and core Rust team member, at the Qcon London 2019 conference.

“I sincerely believe that the languages ​​that will succeed in the future are those that can successfully target WebAssembly.”

WebAssembly is supported today in Chrome, Firefox, Safari, and Microsoft Edge browsers, as well as the Node.js server-side JavaScript runtime. Several groups are also working on a WebAssembly operating system, with Williams pointing to work being done through the WASMER project and by Mozilla through its Crane Lift initiative.

How to get started with web assembly

headshot3.jpg

Ashley Williams, Systems Engineer at Cloudflare.

Image: QCon London

WebAssembly (WASM) is not designed to be a programming language that humans write, although it can be viewed in a human-readable format. Rather, it is a compiler-generated language, based on code written by developers in a higher-level programming language.

Williams says that while in theory it’s possible to compile code written in any language in WASM, in reality you wouldn’t, with the best options currently compiled from the C, C++ and Rust programming languages, rather than from an interpreted language.

“One thing to note about WebAssembly is that it has no GC [garbage collector] and doesn’t have a runtime, you have to compile your runtime on top of your program when using an interpreted language,” she said.

Here are various tools developers can use to get started building and inspecting WebAssembly:

Emscripten

It is a backend for the LLVM compiler that generates WebAssembly from C, C++ and Rust and is used by Unity and Unreal game engines to generate web versions of games.

RustWASM

A compiler for Rust that generates WASM code capable of interacting with JavaScript through JavaScript bindings. It works with JavaScript tools such as NPM, Webpack and Greenkeeper.

Williams says the plan is for the Rust toolchain to also generate JavaScript that can wrap the generated WebAssembly module, so it can be dropped into a browser or Node.js runtime like you would JavaScript. .

AssemblyScript

If you want to experiment with WebAssembly but don’t feel like learning Rust, C, or C++, there are compilers for higher-level languages.

Aimed at JavaScript developers, AssemblyScript is a language that is a subset of the JavaScript spin-off TypeScript, and compiles to WebAssembly through a toolchain called Binaryen.

“Generally, the WebAssembly that this produces isn’t necessarily the fastest or the smallest, but it works great and they’re doing a ton of great work there right now,” Williams says.

WebAssembly Studio

WebAssembly.Studio is a fork of Visual Studio Code and runs in the browser, allowing developers to inspect WASM as compiled from C, C++ and Rust.

The state of WebAssembly

WebAssembly is designed to work with HTML, CSS, and JavaScript in the browser, with the WASM module loaded using JavaScript APIs.

Ultimately, WebAssembly’s goal is not to replace JavaScript but to work alongside it, delivering a level of performance that JavaScript can’t match and enabling developers to write web applications in languages ​​such as C++. and Rust, as well as opening the door to vast amounts of desktop software to be ported to the web.

SEE: Recruitment Kit: Python Developer (Tech Pro Research)

However, WebAssembly is not a finished product, with plenty of room for improvement in both its support, features, and performance.

“WebAssembly is young, what landed in the browser right now is definitely not a fully mature product,” says Williams, giving the example of garbage collection not yet implemented in WASM.

“If you started working with WebAssembly now, you’ll immediately ask ‘Why is my WASM so big and why isn’t it as fast as I want it to be?’.

“That’s because it’s new technology, but that being said, it’s designed to be faster than JavaScript and it’s often faster, and, just because it’s a game of instructions, your programs are going to be much smaller.”

Williams is optimistic about WebAssembly’s prospects, and with many looking to the future of the web as it celebrates its 30th anniversary, she has high hopes for how WebAssembly could transform the platform.

“I believe WebAssembly is going to lead to a future where the apps we build are very different from what we see people doing now.”

Also see