💾 Archived View for gemini.robrohan.com › 2018-05-07-get-into-webassembly.md captured on 2022-04-28 at 17:28:25. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

---

author: rob

date: 2018-05-07 08:00:00+11:00

slug: webassembly

title: It is time to get into Webassembly

---

I've been keeping an eye on webassembly for the past few years, but it hasn't felt ready to be used yet. However, over the weekend I took another look, and, to me, it seems baked enough to start using it "for reals" now.

If you don't know, webassembly is an attempt to create an assembly like language for the web. Instead of writing JavaScript, you'd write in an assembly language which would get your code base to run much faster (sometimes 30x faster from what I have read).

It's not assembly in the `mov 20, b` sense (it has more of a lisp like syntax), but the concept is similar. Regardless of the syntax, almost no one is going to build a web site in assembly, but having this base language allows for porting of higher level languages. The first high level language out of the gate is C.

I created a [webassembly starter project](https://github.com/robrohan/webassembly_starter) for anyone interested in a quick start for building a web application in C. There is a small amount of setup, but if you follow the README it should fall into place. The most difficult part is compiling emscripten (which is about 4 commands on macOS).

Over the years, I've watch a lot of developers move to coffee script or typescript, and I used to joke that JavaScript was going to become assembly language - well it now has! In the [code sample](https://github.com/robrohan/webassembly_starter/blob/master/src/main.c) you can see you can do "inline JavaScript" within C code:

int x = EM_ASM_INT({

Module.print('I received: ' + $0);

return $0 + 1;

}, 100);

This is completely mind boggling, and cool as!