News for hackers. Stuff that matters.
Re:JavaScript is Web Assembly Language and that's OK. by wwwtyro on Friday May 24, 2013 @09:18AM (#5762489)
> Enter asm.js, where the source code is as readable as a compiler's assembly output.

What do you mean? Isn't it roughly as readable as C?

Re:JavaScript is Web Assembly Language and that's OK. by pornel on Friday May 24, 2013 @09:37AM (#5762610)
No, asm.js is not readable, and doesn't look like C nor even typical JS.

Due to very limited set of expressions available it's too hard to write by hand (e.g. no objects, casts required everywhere, one flat array representing memory), so all non-trivial asm.js programs are spit out by compilers that treat it like assembly and preserve very little structure of source programs.

Re:JavaScript is Web Assembly Language and that's OK. by wwwtyro on Friday May 24, 2013 @12:57PM (#5764049)
This Q/A from the asm.js FAQ appears to disagree with you:

Q. Is asm.js a new language?

A. No, it's just (a subset of) JavaScript. An asm.js program will behave identically whether it is run in an existing JavaScript engine or an ahead-of-time (AOT) compiling engine that recognizes and optimizes asm.js—except for speed, of course!

Also, the examples in the spec are completely legible. It looks much like C, in fact.

Re:JavaScript is Web Assembly Language and that's OK. by jerf on Friday May 24, 2013 @09:35AM (#5762593)
No, it's roughly as readable as decompiled executable, without even a symbol table to provide semi-readable names. John Resig has a somewhat reformatted example a couple of pages into this: http://ejohn.org/blog/asmjs-javascript-compile-target/
Re:JavaScript is Web Assembly Language and that's OK. by azakai on Friday May 24, 2013 @11:02AM (#5763212)
To be fair, you can generate asm.js with quite readable names (use -g in emscripten for example). asm.js does not require that you also minify variable and function names (and whitespace), that is orthogonal, and done on all JS these days anyhow.

If you do not minify the output, then asm.js's readability is somewhere in between x86 and C. It's far easier to understand than x86, but it is still definitely less readable than handwritten C because it's machine-generated and optimized.

Re:JavaScript is Web Assembly Language and that's OK. by wwwtyro on Friday May 24, 2013 @12:26PM (#5763855)
I'm not following you. Are you referring to the minimized code that has been beautified? Of course it is not going to be particularly legible. Same for any minified code, asm.js or not.

From the link you gave, the DiagModule function is asm.js, and every bit as readable as C.

Re:JavaScript is Web Assembly Language and that's OK. by jerf on Friday May 24, 2013 @12:56PM (#5764043)
Sorry, I was unclear. In this context, which if you follow back up to arocks' post is in the context of using "View Source" to learn how things are done, I'm referring to the sort of asm.js that comes out as a result of compiler output, not stuff written by hand. The Gist is what I was pointing at. There is no way you're going to read that and learn how, say, the Unreal Engine port does something.

I think people may think I'm trying to be faintly critical, but I'm not. It's just the nature of the beast.

Re:JavaScript is Web Assembly Language and that's OK. by wwwtyro on Friday May 24, 2013 @01:06PM (#5764114)
> I'm referring to the sort of asm.js that comes out as a result of compiler output

That Gist - what is visible from "View Source" after beautification - is not compiled asm.js code. It is not the result of any compilation. It is the result of minification. Most minified code is as illegible as that.

Re:JavaScript is Web Assembly Language and that's OK. by jerf on Friday May 24, 2013 @01:13PM (#5764153)
Yes, it is. (Perhaps not entirely, but it's generally what you're going to find in the wild.) Read under the Gist for the bullet points. It may be minified, but that's not what makes it impossible to understand.

Hand-written asm.js code is not going to be the norm, for the forseeable future, for a variety of reasons. The rules for the grammar are difficult and tedious to manually write. The fact that everything runs in a massive array, so you've got a lot of memory management to write, is going to be a problem. The existence of numbers like 1384465 and 4980736 is what makes that particularly hard to read. Most asm.js code on the web is going to be incomprehensible; the examples you can read are the exceptions, for didactic purposes, not the rule.

Re:JavaScript is Web Assembly Language and that's OK. by wwwtyro on Friday May 24, 2013 @01:38PM (#5764271)
> Yes, it is [compiled]. (Perhaps not entirely...

Wow. No, it absolutely is not. I have no idea what you could possibly mean by "not entirely" compiled.

>The rules for the grammar are difficult and tedious to manually write.

There's nothing difficult about the syntax. It's a subset of javascript.

> The fact that everything runs in a massive array, so you've got a lot of memory management to write, is going to be a problem.

No more difficult than managing memory in C.

> The existence of numbers like 1384465 and 4980736 is what makes that particularly hard to read.

The lack of meaning for those numbers is what makes it hard to read. It wouldn't matter if 1384465 were 2 or "a". It's been minified, so the meaning has been stripped away. I agree that it is hard to read, but it's not a result of using asm.js, it's a result of minification and auto-generating code. There's nothing inherently illegible about asm.js.

> Most asm.js code on the web is going to be incomprehensible; the examples you can read are the exceptions, for didactic purposes, not the rule.

Sure, just like most javascript on the web is incomprehensible, by virtue of being minified or auto-generated.

Re:JavaScript is Web Assembly Language and that's OK. by pekk on Friday May 24, 2013 @09:36AM (#5762606)
Not C written by humans