News for hackers. Stuff that matters.
Re:WebAssembly Specification Prototype by minionslave on Wednesday July 13, 2016 @03:20PM (#12088881)
I have a question about WebAssembly.

1- With WASM, would developing for the web become similar to how desktop apps are written? For example, could I use C# and design a UI in xaml, compile to WASM for the web?

2- No more JavaScript?

Re:WebAssembly Specification Prototype by Klathmon on Wednesday July 13, 2016 @05:05PM (#12089664)
WebAssembly is not a replacement for JavaScript, and (IMO) it most likely won't ever be.

At the very least JavaScript will always be around as a "glue" language to use wasm binaries.

I think of the relationship between JavaScript and WebAssembly as the relationship between Python and C. JavaScript will call out to a wasm binary for some "heavy lifting" and JavaScript will be used to "glue" the data to the DOM. Also like the Python-C relationship, the wasm can be a compile target for non-javascript libraries.

But I honestly don't see writing non-javascript web applications being mainstream any more than it is now at any point in the near-ish future. It's possible (both now and in the future), but it's always going to be a leaky abstraction, or your language will end up being similar enough to javascript that targeting wasm is largely pointless (think TypeScript or Flow).

Re:WebAssembly Specification Prototype by fizzbatter on Wednesday July 13, 2016 @08:23PM (#12090853)
> But I honestly don't see writing non-javascript web applications being mainstream any more than it is now at any point in the near-ish future.

The performance of touching the DOM and browser APIs will be the factor that decides that, imo. I think you may be underestimating how many people are partially or heavily disgruntled at javascript, and would happily replace it if given the chance.

If speed is not an issue, and it's purely by choice of the user, i think there will be a lot of interesting changes to the web in the coming years.

Hell, for many applications i'd even be willing to accept a speed loss to use "my preferred language". And, in the event that certain tasks are indeed too slow, perhaps i'll be able to pass data back and forth between my WASM and JS to let JS deal with the performance critical DOM.

Regardless, i'm quite excited, and hope to see something fruitful from it.

Re:WebAssembly Specification Prototype by modarts on Thursday July 14, 2016 @12:01AM (#12091552)
> how many people are partially or heavily disgruntled at javascript

It's not actually the nightmare many make it out to be with ES6. I actually enjoy writing it quite a bit (I have mainly a functional background)

Re:WebAssembly Specification Prototype by fizzbatter on Thursday July 14, 2016 @11:56AM (#12094877)
Yea, fwiw these days it is much better. But i think the biggest issue is simply the lack of choice. On my OS, i can choose whatever language i want. Whether i choose for preference, or the right tool for the job, i have choices, many of them.

On the web it's.. well, just JS. Some languages that transpile to JS.. but ultimately they're all pretty much just JS.

Re:WebAssembly Specification Prototype by bluejekyll on Wednesday July 13, 2016 @08:59PM (#12090997)
Yes. With this we can finally be less restricted in our language choice.

I think the community of people who want tyoe safe languages is large, and this will the a target for them.

I just hope for Dom bindings through the WASM ABI.

Re:WebAssembly Specification Prototype by douche on Wednesday July 13, 2016 @09:07PM (#12091030)
Javascript is awful. If WebAssembly is anywhere near consistent across browsers, and there are better languages that compile to WebAssembly, I would go that way in a New York minute.
Re:WebAssembly Specification Prototype by yoklov on Thursday July 14, 2016 @12:03AM (#12091559)
If your language of choice comes with a runtime that's not shipped in the browser, WASM doesn't seem like it will make speed into a non-issue, it will just frontload the slowness.
Re:WebAssembly Specification Prototype by fizzbatter on Thursday July 14, 2016 @11:57AM (#12094897)
ftr, when i mentioned speed i was mainly referring to WASM->DOM. So, if that ends up too slow for heavy DOM manipulation (eg, React style diffing/etc), then with any luck we can offload the DOM interactions to JS. Eg, WASM->JS->DOM
Re:WebAssembly Specification Prototype by randyrand on Wednesday July 13, 2016 @08:53PM (#12090972)
Screw that.

Writing glue code sucks.

Define an ABI for interacting with the DOM. And allow WASM compilers to target it.

Re:WebAssembly Specification Prototype by flohofwoe on Thursday July 14, 2016 @03:21AM (#12092175)
I'm pretty sure there will be libs in various languages that allow to talk to the DOM directly (e.g. in C/C++ #include "dom.h"), under the hood they would still call out into JS but the library user wouldn't have to touch Javascript. This is how most of the C API wrappers in emscripten work (e.g. OpenGL wrapper which talks to WebGL). Calling out into JS sounds like a perf hit, but overall it works very well... as long as the JS code doesn't produce too much pressure on the garbage collector, I think this is the main problem with the current JS wrappers. But since DOM operations are slow anyway that shouldn't be a problem (it's fast enough for WebGL, so...).
Re:WebAssembly Specification Prototype by wrmsr on Thursday July 14, 2016 @11:48AM (#12094820)
I've heard that native DOM interaction (no JS middle man) is on their radar via WebIDL. They don't want people reinventing the DOM via custom canvas rendering and such so making DOM manipulation painless is a priority.
Re:WebAssembly Specification Prototype by spankalee on Wednesday July 13, 2016 @03:33PM (#12088988)
WASM doesn't have access to the DOM, or a GC, or very easy interop with JavaScript, so the answer is mostly "no".
Re:WebAssembly Specification Prototype by warbiscuit on Wednesday July 13, 2016 @04:11PM (#12089266)
I hope DOM access comes very close on the heels of the initial design...

Javascript is an interesting language (particularly after it's recent revival), but IMO it's recent jumpstart would never have happened if it weren't for one killer feature: access to the HTML DOM. People would (and have) forgiven many other things, just for the utility of that as the presentation layer.

I certainly would have picked up whatever language the browsers were pushing, where DOM access was a requirement.

Conversely, I remember trying to get java applets to interact with HTML -- you have to message things through a tiny hole to/from javascript; which was (one of the many) things which made everyone hate java applets.

Re:WebAssembly Specification Prototype by comex on Wednesday July 13, 2016 @04:34PM (#12089458)
It depends what you mean by "access". The MVP won't have direct DOM access, but it's not really necessary. WebAssembly code can synchronously and efficiently call JavaScript functions (with numeric arguments), so it should be pretty easy to write a WebIDL-based stub generator to provide natural syntax for calling DOM functions from any given compiled language, with a little JavaScript stub on the other end. A future spec might make things more efficient by providing direct access, but it's really a micro-optimization.
Re:WebAssembly Specification Prototype by pcwalton on Wednesday July 13, 2016 @06:50PM (#12090336)
Well, the tricky part is not getting the basic FFI to work but getting the memory management right. Making sure that DOM nodes that are not part of the document stay alive and that dead nodes die is the hard part, especially if JS/wasm cycles are involved.

(This is not a criticism of wasm, by the way. It's merely motivating potential future GC extensions to the spec.)

Re:WebAssembly Specification Prototype by bluejekyll on Wednesday July 13, 2016 @09:03PM (#12091013)
How does that differ from today? Don't all rendering engines have to deal with that GC now?
Re:WebAssembly Specification Prototype by megalodon on Wednesday July 13, 2016 @04:25PM (#12089385)
I just hope that when it happens we will be able to view and read the source of WASM in the same way we can with javascript now. This is one of the foundations of WWW, please don't turn it into a closed source app store.
Re:WebAssembly Specification Prototype by gsnedders on Wednesday July 13, 2016 @04:28PM (#12089415)
We lost that years ago with minification. Source maps can work as well for WASM as they can for minified JS.
Re:WebAssembly Specification Prototype by megalodon on Wednesday July 13, 2016 @05:08PM (#12089684)
You seem to know a bit about web standards, was minification ever formally accepted by the W3C or did it just happen?
Re:WebAssembly Specification Prototype by gsnedders on Wednesday July 13, 2016 @05:10PM (#12089691)
Just happened. It's just renaming variables and properties, after all—there's no actual change to anything standardised.

As an aside, JS is standardised by Ecma, as ECMAScript: the W3C doesn't have anything to do with it.

Re:WebAssembly Specification Prototype by kuschku on Wednesday July 13, 2016 @04:40PM (#12089506)
Then make browsers require full source maps for every website, or refuse to run them.

That’d be finally a solution.

Or require source maps by law.

EDIT: Why the downvotes? The only way to preserve the right to modify and decompile in the long term is by creating technical or legal measures enforcing it. JS was one technical measure, so now we need alternatives.

Re:WebAssembly Specification Prototype by pcwalton on Wednesday July 13, 2016 @06:52PM (#12090352)
> Then make browsers require full source maps for every website, or refuse to run them.

> That’d be finally a solution.

No, it wouldn't. You'd end up with sites shipping "source maps" that map every function to a randomly generated identifier.

Re:WebAssembly Specification Prototype by jfbastien on Wednesday July 13, 2016 @05:35PM (#12089855)
That would be awfully slow to transfer (or just verify) when most people never view the source map.

What's a "valid" source map anyways?

Furthermore, debugging with sourcemaps is suboptimal. WebAssembly wants to support much better debug information than this.

Re:WebAssembly Specification Prototype by gsnedders on Wednesday July 13, 2016 @05:42PM (#12089901)
And it'd imply you need a source map even with unminified JS. And what's to say the source map maps to non-minified JS?
Re:WebAssembly Specification Prototype by kuschku on Wednesday July 13, 2016 @06:22PM (#12090148)
It’s not about debugging, it’s about the legal "right to decompile", which is intended to give customers and companies the right to take apart products and software they bought (even from competitors), and gain knowledge from that.

It’s also intended to allow them to modify it for their own purposes, and provide the modifications to others who have a license to the original product.

Especially on the web this was finally possible, and now you’re suggesting to take this away again?

Re:WebAssembly Specification Prototype by Matthias247 on Thursday July 14, 2016 @03:15AM (#12092157)
You don't seem to want a right to decompile/disassemble (which you could do in the same form for WASM than for most other languages) but a right to directly view the original source code. Such a right does not exist in general. The owners of the source code (the intellectual property) may give you the possibility to view it, but they could also decide that they don't give it to you. The only exceptions I know of are if the creator incorporates other software parts which mandate releasing the source code, e.g. GPL libraries.
Re:WebAssembly Specification Prototype by rabbitfang48 on Wednesday July 13, 2016 @07:04PM (#12090413)
I know of no country (or other jurisdiction) where a legal "right to decompile" exists.
Re:WebAssembly Specification Prototype by vidarh on Wednesday July 13, 2016 @08:36PM (#12090909)
Many countries allow reverse engineering, and you could infer a "right to decompile" from that in some cases, but as far as I know none of them place any requirement on the source to make it easy.

At most they legally protect someone who decides to run a disassembler or decompiler on a binary from prosecution or lawsuits (but only in as much as you don't use the result to violate copyright or other restrictions).

Re:WebAssembly Specification Prototype by gsnedders on Wednesday July 13, 2016 @07:29PM (#12090558)
The EU has a very, very limited right to decompile for the sake of interoperability.

See Article 6 on http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=CELEX:...

Re:WebAssembly Specification Prototype by kuschku on Thursday July 14, 2016 @06:09AM (#12092669)
And for personal modifications, and so on.

And "copying the decompiled source of the part of MS Word that reads .doc files" counts as covered, so, it's quite a lot.

Especially with websites, where you might want to interact with, or write addons interacting with, WASM threatens those rights.

Re:WebAssembly Specification Prototype by jfbastien on Wednesday July 13, 2016 @08:51PM (#12090962)
Browsers don't create laws. WebAssembly can't legislate. This is really out of scope!
Re:WebAssembly Specification Prototype by kabes on Wednesday July 13, 2016 @05:24PM (#12089772)
Step 1) Replace the 2d library of your desktop GUI language to draw using HTML canvas API. Step 2) Compile to wasm

No need for the DOM anymore... (not saying it's a better approach, but it is technically possible).

Re:WebAssembly Specification Prototype by stupidcar on Wednesday July 13, 2016 @03:38PM (#12089033)
All that is planned though, just not for the MVP: https://github.com/WebAssembly/design/blob/master/GC.md
Re:WebAssembly Specification Prototype by mintplant on Wednesday July 13, 2016 @05:42PM (#12089903)
No idea why you've been downvoted. I'm interning at Mozilla right and as that design document says, GC and DOM access for WASM are very much on people's radar - they just won't make it into the initial roll-out.
Re:WebAssembly Specification Prototype by supster on Wednesday July 13, 2016 @04:58PM (#12089609)
If there is no GC, could a language like Rust or Swift still target WASM?
Re:WebAssembly Specification Prototype by steveklabnik on Wednesday July 13, 2016 @05:00PM (#12089623)
We plan on having Rust target webassembly, and there's already basic support for doing so.
Re:WebAssembly Specification Prototype by brett40324 on Wednesday July 13, 2016 @07:24PM (#12090529)
Where can I learn more about this basic support?

There's the next full stack paradigm right there. I give it two years, and it will be called rustic-asm framework...

Re:WebAssembly Specification Prototype by steveklabnik on Wednesday July 13, 2016 @08:02PM (#12090744)
https://github.com/brson/mir2wasm

It's still very early, and there's other avenues as well: an LLVM backend, for example.

Re:WebAssembly Specification Prototype by brett40324 on Wednesday July 13, 2016 @10:18PM (#12091272)
Cool, i appreciate the link.
Re:WebAssembly Specification Prototype by fizzbatter on Wednesday July 13, 2016 @08:27PM (#12090871)
haha :D. I also have plans for a Rust web framework. Nothing fancy, and it will likely suck, but it's a dream :)
Re:WebAssembly Specification Prototype by DasIch on Thursday July 14, 2016 @04:31AM (#12092390)
Languages that don't require a GC would be fine to begin with, other languages would have to implement a GC in WASM.
Re:WebAssembly Specification Prototype by PudgePacket on Wednesday July 13, 2016 @09:27PM (#12091102)
Rust doesn't use a GC, so it should be fine. Is that what you meant ?
Re:WebAssembly Specification Prototype by fizzbatter on Wednesday July 13, 2016 @08:24PM (#12090856)
DOM and GC are on the plan list thought, fwiw. It will, as far as the planning is concerned.
Re:WebAssembly Specification Prototype by dekimir on Wednesday July 13, 2016 @06:17PM (#12090113)
It's hard to speculate how the culture and philosophy of web development will change, so let's leave that aside and consider what's possible to do. It's certainly possible to compile into wasm a desktop program in a high-level language, even a program with a GUI. When the browser runs that wasm, the user will interact with your GUI instead of HTML elements. See webassembly.github.io/demo.

More excitingly, I presume it will one day be possible to compile a mobile app into wasm and execute it in a browser, achieving instant parity between mobile web and apps.

Re:WebAssembly Specification Prototype by sspiff on Thursday July 14, 2016 @03:13AM (#12092146)
The greatest disparity between mobile and native is the level of sandboxing, browser chrome and restrictions on user interactions reserved by the browser. Taking those away is not what WebAssembly does.

Indeed, taking those away would be breaking the web rather than improving it...

Re:WebAssembly Specification Prototype by Millennium on Wednesday July 13, 2016 @03:45PM (#12089084)
1 - You could use C# (provided that a compiler exists), but this only gets you the language, not the APIs and libraries commonly used by it. In that sense, it's not much different from using Emscripten (a compiler that goes from other LLVM languages to JavaScript) today. For example, XAML won't work unless someone writes a library to translate it into the browser's usual structures. 2 - It's still JavaScript underneath (more accurately, it's asm.js underneath).
Re:WebAssembly Specification Prototype by sp332 on Wednesday July 13, 2016 @04:10PM (#12089263)
asm.js can interpret wasm as a fallback, but once wasm gets built-in to browsers, it won't be JS anymore.
Re:WebAssembly Specification Prototype by bobajeff on Wednesday July 13, 2016 @05:18PM (#12089741)
I've read somewhere that so far the experiments for having asm.js polyfill webassembly isn't looking too promising anymore. I could be wrong though.
Re:WebAssembly Specification Prototype by binji on Wednesday July 13, 2016 @05:35PM (#12089850)
I've made some progress on this, but there's still a way to go: https://github.com/WebAssembly/sexpr-wasm-prototype/commit/8...