4 ms·
> 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?
by wwwtyro 13y ago
> 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?
- jerf 13y agoNo, 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/ http://ejohn.org/blog/asmjs-javascript-compile-target/
- azakai 13y agoTo 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.
- wwwtyro 13y agoI'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.
- jerf 13y agoSorry, 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.
- wwwtyro 13y ago> 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.
- jerf 13y agoYes, 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.
- wwwtyro 13y ago> 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.
- pekk 13y agoNot C written by humans
- pornel 13y agoNo, 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.
- wwwtyro 13y agoThis 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.