Slashdot Mirror


How Converting A C++ Game to JavaScript Gave Us WebAssembly (ieee.org)

Slashdot reader Beeftopia shares "a detailed history of WebAssembly...from one of the developers." IEEE Spectrum reports that "Like a lot of stories about tech innovation, this one started with video games." [Mozilla's Alon Zakai] wanted to take a game he had helped write in C++ and convert it to JavaScript code that would run well on the Web. This was in 2010, and back then, converting C++ to JavaScript was unthinkable... so he started working to adapt an open-source tool that could translate C++ code into JavaScript automatically. He called his project Emscripten... we were able to formalize the permitted JavaScript patterns, to make the contract between Emscripten and the browser completely clear. We named the resulting subset of JavaScript asm.js... I would optimize the JavaScript engine in Firefox to run the resulting code even faster...

This brings us to the present... Emscripten can take code written in C++ and convert it directly into WebAssembly. And there will be ways in time to run other languages as well, including Rust, Lua, Python, Java, and C#. With WebAssembly, multimillion-line code bases can now load in a few seconds and then run at 80 percent of the speed of native programs. And both load time and execution speed are expected to improve as the browser engines that run the code are made better.

They'd started with a C++ game because "If we could make games run well on the Web, other computationally intensive applications would soon follow."

The article -- by Mozilla software engineer Luke Wagner -- remembers that the name Emscripten was a "a mash-up of 'script' from JavaScript and 'embiggen' from the TV show The Simpsons."

8 of 139 comments (clear)

  1. Sounds like a dumb ass by Snotnose · · Score: 4, Insightful

    if you are halfway competent in C/C++ you can see at a glance what a steaming pile Javascript is. Especially the 2010 version of Javascript.

    I don't like C++ for various reasons, but the only language in a good 40 years of programming I've learned to hate is Javascript.

    1. Re:Sounds like a dumb ass by Anonymous Coward · · Score: 4, Interesting

      Wow, modern /.ers really like to dump on people doing fun projects, never mind completely missing the point of the article. Did you even read TFS before making up your knee-jerk response?

    2. Re:Sounds like a dumb ass by Snotnose · · Score: 5, Funny

      I've got some C++ on a microcontroller that detects kids on my lawn and does the yelling for me. Had I written it in Javascript it would activate twice as often for no good reason, and miss real issues 50% of the time.

  2. Re:I see the problem. by Gavagai80 · · Score: 4, Insightful

    It is a good thing, for a handful of uses, which you might run into once a year. Unfortunately the other 99.99999% of the time it'll be used to create monstrosities which every website will shove down your throat.

    --
    This space intentionally left blank
  3. And this is how JavaScript dies by DeplorableCodeMonkey · · Score: 4, Insightful

    And there will be ways in time to run other languages as well, including Rust, Lua, Python, Java, and C#

    It's only a matter of time before TypeScript skips JavaScript and goes straight to WebAssembly. When Python and Ruby can cleanly target WebAssembly and the DOM, it's game over for JavaScript. What'll happen is quite simple. The people who are decent and kinda like JavaScript will jump to TypeScript. Everyone else will write code in something like Python or Ruby. In fact, I'll say right now that I expect that Facebook will rewrite React and GraphQL in TypeScript or one of those languages within no more than a few years of WebAssembly being supported in all browsers.

  4. How hard can this be? by Blackeneth · · Score: 5, Funny

    JavaScript only has 6 commands:

            create_message_box_subscribe_to_my_newsetter()
            create_message_box_take_our_survey()
            create_message_box_our_cookie_policy()
            create_message_box_allow_us_to_send_notifications()
            create_message_box_behind_browser_advertisement()
            create_message_box_behind_browser_clickbait()

    --
    -- Knowledge is power. -- Francis Bacon
  5. People who see the web as documents by tepples · · Score: 5, Informative

    You failed to address the elephant in the room: Javascript is the language of the web browser platform.

    I think the idea is that a lot of people who regularly post comments on Slashdot and SoylentNews don't want the web browser to be an application platform. They see the web as documents, not applications. They point out that much is achievable through link navigation, form submission, and CSS, such as a script-free version of the "Fast Good Cheap" 2-of-3 checkbox demo. If they wanted an application more sophisticated than that, they would download its source code, compile it, and install it.

  6. What could possibly go wrong? by peppepz · · Score: 5, Insightful

    Am I alone in thinking that giving CPU-level access to our browser to ad networks, hackers, scammers, governments* from all around the world with no authentication and no accountability whatsoever** is a bad idea? Haven't we seen what happened in the past with Java and ActiveX***? Moreover, back then at least Java ran "safe" high-level bytecode, whereas this thing will give to honest programmers the joy of buffer-smashing into adjacent variables, and to dishonest programmers the power to mine bitcoins at nearly native speeds! And once the next hip web frameworks start relying on this technology, there's no way we'll be able to disable it if we want to access the Internet as it's intended.

    * in no particular order of undesirability.
    ** the same-origin policy helps but is not enough, we can't make a trust decision every time we click on a URL, especially now that browser authors have made it so difficult to even see what a link points to, or even understand whether something is a link in the first place. Also, web developers tend to include large amounts of third-party code that they do not inspect, and if such code comes in binary form even before they minify it, then they won't be able to audit that code even nominally.
    *** I'm not adding JavaScript to the list. See? I'm not an old person. I like new things!