
Build Your First Thing with WebAssembly - NickLarsen
http://cultureofdevelopment.com/blog/build-your-first-thing-with-web-assembly/
======
tdumitrescu
Nice investigation! A minor point about your description of wasm: "WebAssembly
or wasm is a bytecode specification for writing performant, browser agnostic
web components." The term "web components" already has a pretty specific
meaning referring to the in-progress specs for custom html ui elements and
surrounding technologies (see [https://developer.mozilla.org/en-
US/docs/Web/Web_Components](https://developer.mozilla.org/en-
US/docs/Web/Web_Components)). You probably don't want to overload that term
given how close the domains already are.

~~~
NickLarsen
That's fair. Originally asm.js was named capsule.js but that was taken and
didn't really mean what it was. We could also call it modules but there is
another very related spec out there for that as well. What would you call it
instead?

~~~
Someone
OpenDoc used 'part'. IIRC, all parts had a presence in the GUI, though.

This, I think is just a library or archive (in the ar/ranlib sense;
[https://sourceware.org/binutils/docs/binutils/ar.html#ar](https://sourceware.org/binutils/docs/binutils/ar.html#ar))
of code that the browser loads over the Internet.

Java hit a jackpot calling such a thing a jar, a word that is both shorthand
for "Java archive" and a noun describing a container. That suggests looking at
words such as 'bottle', 'box', 'cask', 'pot' (nice word, but its connotations
do not make it a winner), 'cup', 'amphora', 'pithos' (not well-known enough,
and typically unmovable), 'crate' (taken by rust), or 'vase' but I can't find
a nice alternative interpretation as an abbreviation ('Jug' has a 'j' that
could mean JavaScript, but I think we would be looking for something with a W
for 'web' or I for 'internet') or even something that sounds good ('crate' is
growing on me, but already taken by rust. That shows that other terms might
grow to become acceptable, too. Maybe 'jug' could be such a word?)

~~~
kahnpro
Plus jug will give us great opportunities for immaturity, like hey Bob, can
you take a look at my jugs? Are my jugs too big?

~~~
DelaneyM
I'm not sure if that's a plus (because I think it's hilarious) or minus (as a
top-heavy female developer.)

Have an upvote and a ಠ_ಠ.

------
vonklaus
I suspect webassembly will fail miserably. If it succeeds anywhere it will be
for gaming applications. I could be totally wrong, but most web developers who
build applications and sites will not be likely to embrace this given the
leverage JS provides and the simplicity of use.

Again, I am not extremely against wasm, but this writeup is pretty well done
and my take away was that it was non-trivial to pickup, buggy and has poor
documentation. I am curious who web assembly is for and who is really excited
about it. Is it gaining traction in gaming, and also what am I
missing(serious)?

edit: Can advertisers bypass content blockers by compiling to wasm?

~~~
NickLarsen
We (at Stack Overflow) have a new documentation product coming down the pipe
with an emphasis on examples and I thought it would be awesome if we could
expand our stack snippets feature to languages beyond javascript. A
reproducible example right there on the webpage. In researching existing
solutions, nothing was satisfying, and then I had the idea to just use asm.js
and write an MSIL interpreter. I spoke with some people familiar with asm.js
and decided that it wasn't particularly difficult, but it had a ton of
limitations from js file sizes to ways to get all of the libraries people ask
about uploaded, and of course regular breaking changes in the browser. Wasm
seemed like it could help with some of the issues being a formal web
specification with representatives from multiple browsers.

Other than that, I can see a lot of uses for it, from small neural nets in the
browser to high performance applications like photo editing, and of course
gaming. It might not be for all applications, but it certainly has a spot.

~~~
vonklaus
Nick,

Great writeup. I am a big proponent of the _idea_ of webassembly as I believe
many are. The browser is one of the greatest apps, and it is easy to look past
many of its flaws because it provides a universal environment to develop for.
I have always been a harsh critic of the balkanization apps provide when they
are unneccessarily trying to extend functionality already provided by the
browser and live natively on my device providing virtually nothing but more
access to "my" resources.

That said, while I don't love writing apps in an old IBM GML and pulling in
heaps of scripts to get the functionality I need, it is easy and well
understood (which is why it has proliferated). If we are to change this, I
think an entirely new paradigm would be easier to use and embrace than
something like wasm because the browser has a lot of access to resources and
this has a fairly narrow use-case relative to it's complexity.

I could be wrong, as this technology is super nascent and people as
intelligent and synonomous with the web like BRendan Eich are openly
supporting it, I just don't see it being embraced at the sort of tipping point
neccessary to proliferate.

It will be very hard to build a community of people doing things like you have
here: providing great resources and tutorials and a community of code base to
build on. A new standard or tech must be 10x better than the current one and I
do not feel this is.

~~~
kkarakk
Also you can't trivially copy/debug a web component built using web
assembly(so far) and play with it which is kinda a death sentence for any tech
on the web unless it's championed as being a killer tool for some usecases-
which this doesn't seem to be so far

------
Fej
On one hand, I want to bash WebAssembly because it takes away our ability to
see what we're running on our own PCs. On the other, it helps us slowly get
away from the mess that is modern JavaScript.

~~~
vonklaus
I think "this javascript mess" is largely bourne out of an attempt to mitigate
content blocking. asm.js is pretty fast and I am not sure how much improvement
wasm will provide, but if given access to more of the low-level environment I
am concerned advertisers will implement maliscious code and pop-ups in wasm
that is non-trivially blocked.

~~~
colordrops
It's the same VM as JS, so why would it be any less secure?

~~~
vonklaus
I am not sure exactly how it can be implemented, but I imagine that compiling
and serving a binary file could allow for some maliscious things. My biggest
worry is that many content blockers override js and search scripts for
keywords and functionality which they muitigate. I could see a binary file
executing code which provides pop-ups, advertisements or drm which would be
harder to eliminate than it is now.

I am not 100% sure if this is true, but it seems possible.

~~~
izym
Serving a binary file is in principle no different than serving a string file.
What can be done with WebAssembly today can most likely also be done with
asm.js.

------
wofo
Thanks for the writeup! I had a hard time figuring out how to compile C++ to
WebAssembly a couple of weeks ago and finally gave up given the lack of
maturity of the implementation. I am sure this will help more people get
interested in WebAssembly!

~~~
NickLarsen
I had the exact same problem when I first started. Someone once told me "what
we can throw away to solve this problem", so I kept removing parts until I got
here which I think is currently the easiest way to get started.

~~~
binji
Ultimately you should be able to use your C compiler and generate wasm files
directly, rather than go through asm.js.

There is an experimental backend of LLVM that you can try, but it will require
building LLVM from source currently. Emscripten has an option to do this
automatically, I believe.

You can also write the AST format by hand, which IMO is much easier to do than
writing asm.js by hand, just more verbose. I wouldn't advise anyone do this,
as the format has been changing over time.

Finally, there is work on specifying a true "text format" that is meant to be
used with view-source and directly maps to the binary format. You can see some
proposals if you look at the pull requests in the design repo. When a proposal
is accepted and we implement the tooling, you will be able to generate a
binary directly from this format, which will be much nicer.

~~~
NickLarsen
I'm familiar with the LLVM direct to wasm tool, but I was unable to get it
working using the steps from the emscripten docs. The binaryen toolchain is
pretty easy to digest, but I've been using the emsdk almost exclusively for
the convenience. Once you have to rework part of it from source, I just don't
know enough about it to debug it yet.

Thanks for the info on where to find outstanding proposals.

------
_pmf_
Hey, the intermediate language is actually a nice step up from JS.

------
benkuykendall
Huh, the AST looks pretty human readable. Anyone have tips for writing
WebAssembly without using asm.js? Even a pointer to decent documentation would
be great.

~~~
niftich
Well, if you're comfortable with that AST text-format, check [1] for docs and
examples (the .wast files in the links). If you're super brave, there's hints
about the Binary AST format here [2]

[1]
[https://github.com/WebAssembly/design/blob/master/TextFormat...](https://github.com/WebAssembly/design/blob/master/TextFormat.md)

[2]
[https://github.com/WebAssembly/design/blob/master/BinaryEnco...](https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md)

------
shurcooL
This is super useful and helpful, thanks for writing it up!

------
gscott
I have a problem with making designing websites more complicated. This
snobbery of finding a new complex way of doing something that should be made
easier... not harder.

~~~
thomasfoster96
If you understand the problem - that a dynamically typed, interpreted language
has performance issues that prevent it being useful in computationally
intensive scenarios, but can't be replaced easily - then this solution is
actually quite reasonable.

------
bobajeff
I still see a lot of misunderstanding here about what WebAssembly is. It's not
really a "bytecode" like JVM's. The best simplest way to describe it is a
virtual ISA for compilers to target.

So the languages that make use of it will be compiled languages like C, C++,
Pascal, Fortran etc.

