News for hackers. Stuff that matters.
Re:JavaScript is Web Assembly Language and that's OK. by arocks on Friday May 24, 2013 @08:51AM (#5762369)
One of the endearing qualities of web design and development was how the source was open for everyone (HTML, CSS and JS). Developers could read the code, understand and remix each other's work. This helped in its rapid growth from a design platform to an application platform.

Enter asm.js, where the source code is as readable as a compiler's assembly output. Once again we are back to code that is hard to hack and improve. Sort of similar to the days of Flash except that entire applications are being built on this platform.

It might be a great end user experience, but it is not the best way forward for web development.

Re:JavaScript is Web Assembly Language and that's OK. by k__ on Friday May 24, 2013 @08:57AM (#5762398)
I know, there was a time when people took their scripts from different sites and included then into their own.

But does this still happen?

I mean most of the scripts are minified anyways :\

Re:JavaScript is Web Assembly Language and that's OK. by jiggy2011 on Friday May 24, 2013 @09:03AM (#5762420)
People still do that, when they want a rotating banner effect for their website or whatever.

Once you get into more complex applications it doesn't really make sense to do that anymore.

Re:JavaScript is Web Assembly Language and that's OK. by k__ on Friday May 24, 2013 @09:06AM (#5762434)
I see... maybe if you get fluent enough with JS, you're just faster hacking such little scripts than finding a page, copy it and reassemble it.
Re:JavaScript is Web Assembly Language and that's OK. by jiggy2011 on Friday May 24, 2013 @09:14AM (#5762467)
Well jquery-ui solves this problem to a large extent, if you want something like say a datepicker you can do

$("#datepickerelement" ).datepicker();

and get the functionality you need in a nice reusable package without having to copy and paste giant chunks of code and pollute your global namespace.

Re:JavaScript is Web Assembly Language and that's OK. by jerf on Friday May 24, 2013 @09:31AM (#5762567)
Does it matter anymore, though? Back in "the day", documentation was poor and nobody knew what they were doing. Document is massively better now. Javascript libraries abound, perhaps to a fault. Does anybody learn how to program the web by looking at other people's work now?

In those rare cases I've done this in the last few years, the sum total has always been to find out which CSS property or JS function I didn't know about was being used, and then simply pop that into Google. I certainly didn't stare at their code for any longer than that.

Re:JavaScript is Web Assembly Language and that's OK. by zampano on Friday May 24, 2013 @11:22AM (#5763351)
Wow, I'm still a relative newcomer, but I constantly pull up the CSS and JS for any site that seems interesting. Considering how easy Chrome devtools makes it to play around with sites, I figured most enthusiasts/professionals were doing the same thing.
Re:JavaScript is Web Assembly Language and that's OK. by mistercow on Friday May 24, 2013 @10:57AM (#5763177)
But we already had arrived at the point of unreadable source code with the advent minifiers and tools like Closure Compiler.
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