12 votes

Is WebAssembly the Return of Java Applets and Flash?

8 comments

  1. [8]
    crius
    Link
    I didn't paid any attention to webAssembly, here is a link to mozilla page about it: https://developer.mozilla.org/en-US/docs/WebAssembly Also a little more flavoured article from medium:...

    I didn't paid any attention to webAssembly, here is a link to mozilla page about it: https://developer.mozilla.org/en-US/docs/WebAssembly
    Also a little more flavoured article from medium: https://medium.com/javascript-scene/what-is-webassembly-the-dawn-of-a-new-era-61256ec5a8f6
    Official website: https://webassembly.org/

    The article itself doesn't make a great job at explaining... well, much at all. The only interesting thing it explain is how WebAssembly applications are integrated within the browser and so get access to the html/css of the page. A thing that Flash and Java don't do.

    From my ignorant point of view then, my question is: Don't we have already javascript then?

    If you're looking for more info I suggest you give a look to the medium's article.

    1 vote
    1. [5]
      meghan
      Link Parent
      The simple answer is that yes we do have JavaScript but not everyone likes JavaScript. And as mentioned in the article it would be impossible for the browsers to implement a runtime for every...

      The simple answer is that yes we do have JavaScript but not everyone likes JavaScript. And as mentioned in the article it would be impossible for the browsers to implement a runtime for every language developers want to use. The answer that wasm takes to be a language agnostic format that other languages can compile to, essentially providing a way for every language to come to the Web (provided the tooling to developed for said language to compile to wasm)

      6 votes
      1. [3]
        Emerald_Knight
        Link Parent
        You know, I thought I had a general idea of what wasm is, but I never really cared enough to consider how it was implemented or how it could be used. From what I'd read in the past, it sounded...

        You know, I thought I had a general idea of what wasm is, but I never really cared enough to consider how it was implemented or how it could be used. From what I'd read in the past, it sounded like it was assembly emulation through JS. Your mention of building other languages on top of it piqued my interest, though, and looking into it again it's clear that my understanding was way off.

        Wasm honestly sounds pretty great. It seems like it will provide a way to distribute web applications written in virtually any language with very little developer burden for setup or configuration and no need for the average user to do anything more than run an up-to-date browser that supports wasm. Especially with the current state of JS development where you can't do anything anymore without using transpilers, polyfills, bundlers, several different package managers, and a bunch of other bleeding-edge tech before you can use one tiny little utility inside a 3rd-party library that you desperately need so you can support a feature that you can't reasonably implement otherwise because emulating anything remotely close to the functionality of that library would require an entire dev team of its own (I'm not bitter at all, I swear).

        I'm actually looking forward to the prospect of a wasm IDE where you can install a language you want supported, write your code in that language, click "build", and have a module ready to be dropped into a directory somewhere and loaded directly into a webpage with minimal effort (or, for mixed wasm and JS, just selecting which directories to run build operations on).

        8 votes
        1. crius
          Link Parent
          This is low effort comment but Man, how I feel you right now :-/ Sometimes I feel like I work more for those third party github repository, fixing their bug and stuff, than my own projects..

          This is low effort comment but

          JS development where you can't do anything anymore without using transpilers, polyfills, bundlers, several different package managers, and a bunch of other bleeding-edge tech before you can use one tiny little utility inside a 3rd-party library that you desperately need

          Man, how I feel you right now :-/
          Sometimes I feel like I work more for those third party github repository, fixing their bug and stuff, than my own projects..

          4 votes
        2. meghan
          Link Parent
          That's the dream :D

          That's the dream :D

          1 vote
      2. crius
        Link Parent
        You're absolutely right. I totally missed that wasm is, roughly saying, a wrapper for any possible language you want to use in which you can create a self-contained application. It is actually a...

        You're absolutely right. I totally missed that wasm is, roughly saying, a wrapper for any possible language you want to use in which you can create a self-contained application. It is actually a pretty good idea and the main reason is that it's not just "a plugin" but a standardised component of the web

        4 votes
    2. [2]
      dblohm7
      Link Parent
      (I am a software engineer at Mozilla) Allow me to offer you a bit of history on how WASM came to be. About five years ago, give or take, some of the engineers who work on SpiderMonkey, our...

      Don't we have already javascript then?

      (I am a software engineer at Mozilla)

      Allow me to offer you a bit of history on how WASM came to be.

      About five years ago, give or take, some of the engineers who work on SpiderMonkey, our JavaScript VM, realized that there was a way to annotate JavaScript in such a way that the code becomes much easier for the JIT to process. If JS code were to be consistently annotated, the result would be significantly faster execution than regular JS. This is because these annotations are hints that allow the engine to avoid type inference and allow the JIT to generate better code. These annotations are also perfectly valid JS, so any JS engine may execute the code. This annotation format was called asm.js.

      As an example (from the asm.js spec):

      function add1(x) {
          x = x|0;
          return (x+1)|0;
      }
      

      This might look a little bit strange to you: Why is that code OR-ing zero, which is an identity, mathematically speaking? The reason is because, to the JS engine, that inert OR coerces the resulting type of the expression into an integer. Now the JS engine knows that the value is an integer and its JIT can optimize for it.

      SpiderMonkey was the first engine to add specific optimizations to improve asm.js performance. Eventually the other browser vendors got on board and built a new standard called WebAssembly. While WASM is definitely different from asm.js, and (from my understanding) has evolved into its own bytecode, it definitely borrows a lot of ideas from asm.js.

      3 votes
      1. crius
        Link Parent
        Ehi, thanks for the nice story, it's cool to have a chance to read some of the "behind the scene" that happens in big names like mozilla :)

        Ehi, thanks for the nice story, it's cool to have a chance to read some of the "behind the scene" that happens in big names like mozilla :)