News for hackers. Stuff that matters.
Re:The JavaScript Problem by kenjackson on Saturday April 26, 2014 @10:40PM (#7653681)
If you want to build a web app in Haskell instead of the web's true lingua franca, all you're accomplishing is making it harder to hire and harder to collaborate.

We should be making the web multi-lingual. It's kind of absurd that we've built these great abstractions over HW and few people ever think about writing machine language. But for the web, an abstraction over several abstractions, we're largely stuck with a single language and seemingly little real effort to build a Multilanguage abstraction.

If you told me 20 years ago about what the web would become, I'd be amazed. If you went on to say that all programming would be in a single language -- I'd think you were crazy, yet here we are.

The web should have added 1st class support for plug-ins, rather than the direction we went to effectively abolish plugins from browsers.

Re:The JavaScript Problem by jmspring on Saturday April 26, 2014 @10:52PM (#7653711)
Browsers should not be multi-lingual -- more bloat.

The "compile X to javascript" movement has things half right. Unfortunately the "compile to" is Javascript. I wish the language the browsers implemented was something more modern, strong typing, etc. But I am not sure that will happen.

Re:The JavaScript Problem by AnthonyMouse on Sunday April 27, 2014 @01:09AM (#7654065)
The issue is that the "compile to" thing shouldn't be another programming language at all. It should be something like Java bytecode. Except not actually Java bytecode, because Java bytecode was made specifically for Java. You want something designed to be an intermediary representation between code in any arbitrary language and native instructions for any arbitrary architecture.

In theory you could use Javascript as that thing, but it wouldn't be very efficient. On the other hand, what you could do is create a compiler that compiles to both bytecode and Javascript, and then give the Javascript to older browsers that don't support bytecode yet.

Re:The JavaScript Problem by acqq on Sunday April 27, 2014 @02:37AM (#7654194)
If you think about it, bytecode you wish just doesn't exist, whereas JavaScript does and it works:

http://mozakai.blogspot.co.at/2013/05/the-elusive-universal-...

Re:The JavaScript Problem by _random_ on Sunday April 27, 2014 @07:48AM (#7654756)
The point is that we have something that sucks, not that we don't have anything at all.
Re:The JavaScript Problem by flohofwoe on Sunday April 27, 2014 @05:13AM (#7654461)
As an example, Portable Native Client is "proper byte code" (simplified LLVM IR), but client-side compilation takes multiple times longer then AOT-compiling the same code from asm.js (the NaCl team is working hard on improving this though). The download size is also almost the same (if compressed). Performance isn't that much better either, so for every practical purpose "real" byte code isn't automatically better then sending (compiled and compressed) "source code" over the wire.

I'm even getting worse startup times for a "cold start" for the same code compiled to native OSX then for starting the same demo as emscripten version, (presumably because the native version first needs to load a lot of DLLs).

Re:The JavaScript Problem by teacup50 on Sunday April 27, 2014 @02:45PM (#7656214)
On the other hand, because PNaCL is a sane IR, its composeability and implementability vastly exceeds that of asm.js, which requires not only a full JavaScript stack, but additionally, a complex JavaScript JIT system capable of executing it with additional asm.js-specific optimizations.

I can take PNaCL today and deploy it on alternative stacks, irrespective of the web stack. I can inter-operate cleanly with alternative libraries and environments, I can adopt efficient host platform ABIs, I can run it with a sandbox or without. I could even use it as a generic cross-platform sandboxed in-kernel driver layer.

Moreover, should NaCL/PNaCL be successful, there exists the possibility for optimization on the silicon-level via the introduction of new instruction sets that optimize for in-process sandboxing of untrusted code, much in the same way that trap-and-emulate VMs led to much higher performing silicon-implementations of the same ideas.

Issues of performance can be solved given a well-designed system that applies only as much complexity as is needed, at the level that it is needed. asm.js is a hack inserted at an inappropriate layer of the technology stack; NaCL/PNaCL is a coherent compositionally-sane design that opens the door to later optimizations and significant improvements of the underlying technologies on which it rests.

Re:The JavaScript Problem by baddox on Sunday April 27, 2014 @02:11AM (#7654162)
If there exists a tool that compiles your language of choice to JavaScript, and the stuff you write in your language of choice works on modern browsers and is stable and performant, why do you care that it's JavaScript being compiled to and not byte code?
Re:The JavaScript Problem by peterashford on Monday April 28, 2014 @08:54PM (#7664186)
Because JS will always be compromised by being JS shoe horned into a role it wasn't designed for and not byte code optimised for the purpose at hand.

Shoe horning technologies into roles they weren't intended for could describe the entire scope of why the Web sucks (e.g.: HTML mixing presentation with semantics).

Re:The JavaScript Problem by jmspring on Sunday April 27, 2014 @03:55AM (#7654329)
I agree something w/ "byte code" would be that thing. Said "byte code" would deal with types and such.

Now-a-days that "thing" is "javascript" and it has implementation nuances that depend on browser/runtime environment.

Re:The JavaScript Problem by kenjackson on Saturday April 26, 2014 @11:47PM (#7653866)
JavaScript and HTML are a lot more bloat than machine language code written to the wire.

Writing in a language appropriate to the task is almost always the right tradeoff.

Re:The JavaScript Problem by bzbarsky on Sunday April 27, 2014 @01:37AM (#7654097)
> JavaScript and HTML are a lot more bloat than machine language code written to the wire.

http://mozakai.blogspot.com/2011/11/code-size-when-compiling... suggests otherwise in a head-to-head comparison: C code compiled to both a platform-native binary blob and JavaScript, then both gzipped (standard practice for any large JS file on the web).

And if you're talking platform-dependent machine code, that's likely _worse_ on the wire in practice, because unlike a platform-independent representation you can't do edge caching or other sorts of intermediate caches. But maybe you meant a virtual machine (i.e. what people ask for when they want a common bytecode)?

Re:The JavaScript Problem by kenjackson on Sunday April 27, 2014 @01:45AM (#7654117)
That's not how you measure bloat. There's a huge runtime associated with that JS code, and you ignored performance.
Re:The JavaScript Problem by bzbarsky on Sunday April 27, 2014 @10:33AM (#7655194)
Ah, you mean client memory bloat, not transfer bloat (i.e. pageload time). That part was not very clear at all.

You still need a nontrivial runtime (a la PNaCl) if you're going to provide the sort of sandboxing guarantees for the code people want for code that runs without explicit user opt-in. Or is that a non-goal in your case? In that case, I'd like to understand the problem you're trying to solve, since it sounds different from the one JavaScript in web browsers is solving.

I agree that things like asm.js have a performance hit compared to just running an unsafe binary blob. So does PNaCl (though the hit there is different from the asm.js hit: it has somewhat faster steady-state, but worse startup performance). Again, if you're not talking about something that has the same safety guarantees as JS and PNaCl you're comparing apples to oranges.

Re:The JavaScript Problem by _delirium on Sunday April 27, 2014 @12:53AM (#7654025)
I probably wouldn't invent JS if I were tasked with coming up with a bytecode for the web. But how bad is it, on the overall scale of things? I mean, x86 is not a great ISA, and yet has prospered, despite some real nonsense corner cases and an anemic register set. Is JS bad as a bytecode the way that x86 is bad as an ISA, or bad at a different level?
Re:The JavaScript Problem by AnthonyMouse on Sunday April 27, 2014 @01:28AM (#7654087)
There is a degree to which you can make anything do anything. Using JavaScript as bytecode is actually really easy if you don't care about performance whatsoever. And if you get together a group of smart people who try very hard for a long time, I'm sure you could even get it to have reasonable performance. Especially if the people writing the interpreter are talking to the people writing the compiler.

But why would you actually do that as a long-term solution? JavaScript isn't an ISA. It's not hard-coded into anything. You don't have to throw away all the existing JavaScript code to start supporting something else in addition to it. All you would have to do is write code to support whatever bytecode you actually want to use and contribute it to the major browsers.

Re:The JavaScript Problem by BugBrother on Sunday April 27, 2014 @06:10AM (#7654559)
I came into this discussion many hours late, but I have to ask: Why are people discussing as if asm.js didn't exist?! It is fast. (It even support integers!)

To me, asm.js looks like a bad kludge -- and a great road ahead, just extend it a little bit over the next decade with the stuff compiler writers will clamor for.

Am I missing something?

Re:The JavaScript Problem by AnthonyMouse on Monday April 28, 2014 @02:05AM (#7658437)
What you're missing is that there is no need to do that. Using JavaScript as an intermediary representation for other languages on a permanent basis is kind of ridiculous. Improving browser support for JavaScript-as-IR provides no benefit over adding support for a "real" IR and introduces superfluous complexity which is the enemy of both performance and security.

Compiling other languages to JavaScript is a tolerable transition mechanism while browsers that don't support something better are still popular, but trying to improve the ability of browsers to interpret compiled-to-JavaScript code from other languages is farcical -- if you're going to update the browser then update it to support something better than JavaScript, not to improve the performance of the horrible legacy transition kludge.

Re:The JavaScript Problem by BugBrother on Monday April 28, 2014 @01:25PM (#7661450)
I don't disagree with anything you wrote, except the first sentence.

But I'm cynical about the possibility to get a new bytecode standard out, without e.g. MS sabotag... extending it. Half the value of asm.js should be that if there is a working system already in place, the motivations for such shenanigans lessens.

Re:The JavaScript Problem by AnthonyMouse on Tuesday April 29, 2014 @12:24AM (#7664951)
EEE wouldn't work here. That only works when you have overwhelming market share. Microsoft has basically no browser market share on mobile and even on the desktop they no longer have so much that developers can afford to ignore everything else.

The way to handle Microsoft in a situation like this is to ignore them. Support the same IR on Firefox, Chrome and Safari and then Microsoft can play along or go home. At that point the worst they could do is implement an extended version that allows sites made for all browsers to work with IE but then encourage developers to make sites using Windows-specific features that won't work on other platforms. That's effectively what they tried with Silverlight and you see how far that got them.

Re:The JavaScript Problem by bratsche on Sunday April 27, 2014 @12:57AM (#7654035)
Why do you care what the target of the compile is if you're happy with the language you're writing in? That seems like being upset that some code you wrote in a language you like might be running on some processor you don't like.
Re:The JavaScript Problem by Twirrim on Sunday April 27, 2014 @01:43AM (#7654106)
Because it requires some really difficult conversion work under the surface. For example, JS has no concept of integers. To shoe-horn other languages in involves a lot of extra work, which by nature is going to be less efficient. Worse, the javascript engine's JIT can't take advantage of some of the semantics of the language being converted, e.g. if the JIT knew for sure that the number was an int, it could take advantage of that in various ways, or make a smarter decision based on the known performance characteristics of the hardware it's running on.
Re:The JavaScript Problem by SiVal on Sunday April 27, 2014 @04:49AM (#7654416)
because it's inevitably a leaky abstraction
Re:The JavaScript Problem by stplsd on Sunday April 27, 2014 @01:19PM (#7655900)
Jesus, the next time I will read phrase 'leaky abstraction' I am going to throw up.
Re:The JavaScript Problem by tim333 on Sunday April 27, 2014 @04:01AM (#7654340)
I guess Google's Dart is trying to go that way. Not sure it's going to get there though.
Re:The JavaScript Problem by cbhl on Sunday April 27, 2014 @12:41AM (#7653994)
The web was multi-lingual, it's why script tags have a "type" parameter.

I personally think that the death of plugins came about as the result of the iPhone, because x86 binary plugins won't run on an ARM-based phone.

Re:The JavaScript Problem by chipotle_coyote on Sunday April 27, 2014 @03:28AM (#7654270)
Uh, scripts aren't plugins, right? In theory there could be other scripting languages for use in web browsers, which is what the "type" attribute would have been used to indicate. It's just that nothing else ever really took off. Other than Microsoft's VBScript, the only browsers I can think of that supported other scripting languages were early proof-of-concept attempts like Grail.

I think you're a bit confused about browser plugins in general here. They're OS-specific and CPU-specific. I can run Linux, Windows and OS X on a MacBook, but I need OS-specific versions of both the browser of my choice for each one and the browser plugins of my choice for each one. If the iPhone has helped contribute to the decline of plugins, it's because iOS doesn't support them at all, full stop -- if it did, though, they'd have needed to be compiled in iOS-specific versions even if the iPhone used x86 chips.

Re:The JavaScript Problem by cbhl on Monday April 28, 2014 @01:18AM (#7658304)
I was responding to two statements in one comment; I apologize for the confusing non-sequitur.

I do agree that plugins are OS and CPU specific, but I think the popularity and explicit lack of support in iOS and Mobile Safari (which, to my understanding, are stripped down ports of OS X and Safari) really caused web developers and their clients to move off of Flash (and other plugins). For a number of years, Adobe shipped a version of Flash for Android, and I'm under the impression that they were always willing to port it to other platforms/devices if paid enough money (since the Linux binaries had an explicit restriction from inclusion in devices; you could only use them with general-purpose PCs). Java ME ran on phones for years, too, although I don't recall anyone shipping a mobile browser with Java SE plugin support. If someone (a client or web developer) wanted their website to work on iPhone, they had to remove the plugins, and I think many people just started designing around that constraint.