News for hackers. Stuff that matters.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by jerf on Wednesday February 18, 2015 @04:28PM (#9071064)
"For example, will asm.js eventually take over traditional web development? Theoretically, you can compile any compiled language to asm.js, so you'll have a lot more choice for the language you want to use to create your webapps."

I've outlined this progression before, which seems obvious to me, but I haven't seen anyone else discuss it.

    1. Get asm.js into every browser.
    2 or 3. Observe that asm.js is very verbose, define a simple
            binary bytecode for it.
    3 or 2. Figure out how to get asm.js decent DOM access.
The last two can come in either order.

And the end result is the language-independent bytecode that so many people have asked for over the years. We just won't get there in one leap, it'll come in phases. We in fact won't be using Javascript for everything in 20 years [1], but those of you still around will be explaining to the young bucks why certain stupid quirks of their web browser's bytecode execution environment can be traced back to "Javascript", even when they're not using the increasingly-deprecated Javascript programming language.

[1]: https://www.destroyallsoftware.com/talks/the-birth-and-death...

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by beagle3 on Thursday February 19, 2015 @01:58AM (#9072806)
> Observe that asm.js is very verbose, define a simple binary bytecode for it.

I suspect that is never going to happen, for two reasons:

1) verbosity, on its own, does not make a difference on the web - HTML and Javascript are both generally super verbose, and haven't had any accepted "simple binary encoding" designed for them in those 20 years. What does get implemented is minifiers and compressors (gzip encoding or otherwise), both of which will provide benefits to asm.js comparable to what a bytecode would, and would not require any buy-in from browser maker (the same attribute that has made asm.js successful and PNaCL unsuccessful so far).

2) Historically, anything that is not backwards compatible and does not degrade gracefully is NOT easily adopted by Browser makers, or by websites, unless it provides something that cannot be achieved without it (e.g. WebGL gets some adoption because there is no alternative; but ES6 will get little to non in the next 3 years except as a source language translated to ES5)

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by comex on Thursday February 19, 2015 @02:42AM (#9072906)
Well, if such a bytecode were being standardized, someone would surely write a shim JS library to convert it to JavaScript on browsers that didn't have native support yet. And I think the idea of making a binary format would be more popular for a sublanguage which is essentially guaranteed to be machine-generated and inscrutable, especially given that I've seen a lot of commenters here and elsewhere have a knee-jerk reaction against the idea of using JavaScript syntax, than for HTML/CSS/JavaScript, which have a long history of being written and read manually without any (de)compilation steps, even if most big webapps are minified.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by beagle3 on Thursday February 19, 2015 @01:27PM (#9075814)
But it works the other way around: it will not be standardized before there's an implementation. If it ever happens (which I think is unlikely), the standardization will follow the shim.

And the knee jerk reactions are meaningless. The people who ship stuff don't seem to mind, and they are the ones who make things matter.

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by ndesaulniers on Wednesday February 18, 2015 @07:37PM (#9071825)
Hey, you're good at this. ;)

It's funny to see that people so opposed to JS are too short sighted to see that asm.js could enable what they've wanted all along. Look at that!

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by cpeterso on Thursday February 19, 2015 @12:47AM (#9072623)
asm.js is a cross-platform bytecode; it just happens to be ASCII and look like JS. :) Arguments against asm.js as a bytecode are mostly about aesthetics and "elegance".

http://mozakai.blogspot.com/2013/05/the-elusive-universal-we...

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by adamnemecek on Wednesday February 18, 2015 @05:48PM (#9071465)
I think that eventually we might ditch DOM and use WebGL or canvas or something instead of it, like on the desktop.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by ndesaulniers on Wednesday February 18, 2015 @07:38PM (#9071830)
Maybe, as the DOM becomes more loaded with more abstractions, people will start re-implementing abstractions the DOM already provides; just the subset of abstractions they want. Whether their implementation can beat the native code of the DOM, and the bandwidth concerns of reshipping the same logic is another story.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by spyder on Thursday February 19, 2015 @04:26AM (#9073171)
Yea, it's already happening with React and other frameworks which are using virtual DOM.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by munificent on Wednesday February 18, 2015 @08:21PM (#9071955)
And throw accessibility out the window. Sorry visually-impaired people. The web of the future isn't for you. :(
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by tree_of_item on Wednesday February 18, 2015 @08:40PM (#9071999)
You can have accessibility without the DOM, and really the DOM is not such a great way to do this anyway. Just do things like write explicit audio-only interfaces.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by bzbarsky on Wednesday February 18, 2015 @09:22PM (#9072104)
That's a pretty narrow view of "accessibility". For example, you just assumed that your user can't see (or can't see very well?) but can hear.

Users who are deaf and blind? Out of luck. Users who are deaf and not blind but need your thing zoomed to a larger size? Maybe out of luck maybe not (depends on whether the WebGL app detects browser zoom and actively works to defeat it like some do). Users who are deaf and not particularly blind but happen to not be able to tell apart the colors you chose to use in your WebGL? Also out of luck.

What the DOM gives you is a semantic representation that the user can then have their user agent present to them in a way that works best for them. Reproducing that on top of WebGL or canvas really is quite a bit of effort if you really want to target all users and not just a favored few groups.

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by tree_of_item on Wednesday February 18, 2015 @09:25PM (#9072116)
I can't reply to bzbarsky for some reason, but:

I assumed we were talking about vision impairment, because that's what the comment I replied to mentioned. Of course you can implement whatever else you want as well.

I question this "semantic DOM" idea: the trend has been towards filling the DOM with tons of crap in order to make applications, not documents. Do accessibility agents even work well on JavaScript heavy sites today?

Accessibility can and will be had without the DOM; while it is a concern, it shouldn't prevent things like WebGL + asm.js apps on the web.

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by bzbarsky on Wednesday February 18, 2015 @10:01PM (#9072191)
No idea why you couldn't reply to me, but....

My point is that visual impairment is not mutually exclusive with other impairment, even though people often assume it is, consciously or not. This is an extremely common failure mode, not just in this discussion.

And while of course you _can_ implement whatever else you want, in practice somehow almost no one ever does. Doubly so for the cases they don't think about or demographics they decide are too small to bother with.

How well accessibility agents work on JS heavy sites today really depends on the site. At one end of the spectrum, there are JS heavy sites that still use built-in form controls instead of inventing their own, have their text be text, and have their content in a reasonable order in the DOM tree. At the other end there are the people who are presenting their text as images (including canvas and webgl), building their own <select> equivalents, absolutely positioning things all over the place, etc. Those work a lot worse.

You are of course right that accessibility can be had without the DOM, but "webgl" is not going to be it either. Accessibility for desktop apps typically comes from using OS-framework provided controls that have accessibility built in as an OS service; desktop apps that work in low-level GL calls typically end up just as not-accessible as your typical webgl page is today. So whatever you want use instead of the DOM for accessibility purposes really will need to contain more high-level human-understandable information than which pixels are which colors or what the audio waveform is. At least until we develop good enough AI that it can translate between modalities on the fly.

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by amelius on Thursday February 19, 2015 @04:44AM (#9073222)
Speaking about AI, is it really that hard to do the OCR'ing of the images? I'm no expert, but I was under the impression hat this was a solved problem.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by SixSigma on Thursday February 19, 2015 @04:31AM (#9073179)
> I can't reply to bzbarsky for some reason

there's a rate limit to stop threads exploding

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by RussianCow on Wednesday February 18, 2015 @06:46PM (#9071655)
You use WebGL to create standard GUI applications on the desktop? WebGL and canvas are in no way replacements for the DOM.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by adamnemecek on Wednesday February 18, 2015 @06:59PM (#9071697)
E.g. Mac OS X uses OpenGL to render GUI, I guess I should have made myself more clear.

> WebGL and canvas are in no way replacements for the DOM.

That's kind of debatable. If you have access to a fast graphics layer from the browser, you can build a DOM replacement of sorts. I think that famo.us works kind of like that.

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by pavlov on Wednesday February 18, 2015 @07:34PM (#9071815)
It's true that OS X uses OpenGL for GUI compositing, but that's only the lowest level. Above, there's a very important piece of the GUI stack called Core Animation which provides layer compositing.

Core Animation is used by both the native GUI as well as the browser DOM. When you use layer-backed compositing on a web page (e.g. CSS 3D transforms), WebKit implements it with a Core Animation layer. So DOM-based rendering enjoys the same benefits of GPU-accelerated compositing as native apps -- although obviously with rather different semantics since HTML+CSS doesn't map directly to Core Animation.

If you implement your own GUI framework on top of WebGL or Canvas, you're not getting Core Animation compositing for free, so you need to replicate that functionality in your custom framework. (This applies equally to native apps: a WebGL app is equivalent to a Cocoa app that renders everything into a single OpenGL view, and a HTML Canvas app is equivalent to using a single CoreGraphics view.)

I don't think the WebGL/Canvas route makes sense for most apps other than games and highly visual 3D apps. You'll just spend a huge amount of time building your own implementations of all high-level functionality that is already provided by the OS and/or the browser: layer compositing, text layout, view autosizing, and so on. If you're doing standard GUIs, why go to all that trouble?

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by RussianCow on Wednesday February 18, 2015 @07:57PM (#9071881)
> You'll just spend a huge amount of time building your own implementations of all high-level functionality that is already provided by the OS and/or the browser

Not only that, but you can't make a 100% guarantee that your implementation will look and work exactly the same as the native one on the underlying OS. For instance, I can re-create all the native Windows UI controls and re-implement all their behavior in exactly the same way, but what if the user has a custom theme installed? Everything breaks. (WPF has a similar problem.)

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by adamnemecek on Wednesday February 18, 2015 @07:48PM (#9071852)
I agree that it would be a lot of effort to pull off since you'd have to duplicate a lot of the standard OS features in the browser but if eventually the DOM becomes an even bigger bottleneck, it might be a viable solution.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by RussianCow on Wednesday February 18, 2015 @07:31PM (#9071808)
To some degree, yes. You just have to be able to re-use system UI controls like fields. So you wouldn't be able to just use WebGL/canvas/whatever in place of the DOM, you'd need to come up with a new API.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by adamnemecek on Wednesday February 18, 2015 @07:44PM (#9071843)
I know. I was thinking that there'd be something like Qt that would render the widgets using WebGL.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by RussianCow on Wednesday February 18, 2015 @08:16PM (#9071934)
Until the web becomes the dominant operating system, I don't think that's reasonable because you'd have to implement an entire UI kit (with all UI components, behaviors, animations, etc) but can't guarantee that it will behave at all like the underlying OS. There's only so much you can re-create in the browser.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by runeks on Wednesday February 18, 2015 @07:28PM (#9071796)
Perhaps it's to make it backward compatible, so that, for example, the traditional DOM is implemented as a Javascript library that parses HTML and renders it onto a WebGL surface?
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by coldtea on Wednesday February 18, 2015 @06:57PM (#9071691)
>You use WebGL to create standard GUI applications on the desktop?

Increasinly high end apps do.

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by RussianCow on Wednesday February 18, 2015 @08:00PM (#9071888)
Graphically intensive apps do it for performance. But the tradeoff is you lose all the native UI controls that the OS gives you--form fields, text selection, animation, etc. So I don't think replacing the DOM with OpenGL or similar is a good solution for general-purpose apps.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by adamnemecek on Wednesday February 18, 2015 @08:05PM (#9071903)
All of those would be implemented in a framework.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by bzbarsky on Wednesday February 18, 2015 @09:25PM (#9072117)
Yes, they already are. That framework is called the DOM. People keep complaining about it and trying to come up with replacement frameworks that end up slower and less capable...

The DOM definitely has its problems, mind you. Investing some time in designing a proper replacement for it is worth it, as long as people understand going in that the project might well fail.

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by coldtea on Thursday February 19, 2015 @05:08AM (#9073292)
>Yes, they already are. That framework is called the DOM. People keep complaining about it and trying to come up with replacement frameworks that end up slower and less capable...

The ones I've seen are actually faster -- Flipboard for one gets to 60fps scrolling on mobile, IIRC. And of course all WebGL based interfaces on native mobile apps that re-implement parts of Cocoa Touch et al, are not that shabby either.

Sure, it doesn't have as much accesibility, but that's something that can be fixed in the future (and of course people needing more accessibility can always use more conservative alternatives).

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by adamnemecek on Wednesday February 18, 2015 @09:39PM (#9072143)
Which framework has tried to replace the DOM?
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by bzbarsky on Wednesday February 18, 2015 @09:50PM (#9072169)
None have tried to replace all of it that I know of.

People have tried to replace things like text editing (with canvas-based editors), CSS layout of the DOM (with various JS solutions involving absolute positioning), native MathML support (MathJax; this one has of necessity done better than most, because of so many browsers not having native MathML support). There are a bunch of things out there that attempt to replace or augment the built-in form controls, with varying degrees of success.

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by xxgreg on Saturday February 21, 2015 @04:34AM (#9085155)
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by adamnemecek on Wednesday February 18, 2015 @10:22PM (#9072252)
That's my point. Currently, you cannot really replace the DOM since that's kind of the extent of the exposed APIs.

None of the projects that you mention are really relevant to the discussion. I agree that they didn't change shit but it's precisely because they are still built on the DOM and cannot really go below that in the abstraction layer.

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by coldtea on Thursday February 19, 2015 @05:12AM (#9073302)
>I agree that they didn't change shit but it's precisely because they are still built on the DOM and cannot really go below that in the abstraction layer.

There exist UIs done in Canvas and WebGL that are arguably below the DOM in the "abstraction layer" and don't need to use much more DOM nodes besides opening a canvas/gl panel...

(Most full screen 2G/3G web games fall into this, for starters, and those are in the tens of thousands. But there are also lotsa apps).

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by comex on Thursday February 19, 2015 @02:45AM (#9072918)
Flipboard's from the recent story? The resulting site breaks accessibility and the layout obviously has less capability, but it's certainly not slower.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by adamnemecek on Thursday February 19, 2015 @03:51AM (#9073070)
Huh, that's actually seeming not that dissimilar from what I had in mind.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by frik on Thursday February 19, 2015 @12:50AM (#9072631)
You can use HTML-DOM and WebGL together (overlays, or render as texture).

The WebGL support could be improved in Internet Explorer.

Please vote: https://wpdev.uservoice.com/forums/257854-internet-explorer-...

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by amelius on Thursday February 19, 2015 @05:15AM (#9073316)
Is it possible to mix them, while showing, for example, videos, which are clipped by paths or partly obscured by overlaying elements?
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by frik on Thursday February 19, 2015 @01:33PM (#9075864)
I would say yes e.g. with CSS Regions and WebGL. The other way around you have to render the HTML and the video on textures.
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by seanmcdirmid on Wednesday February 18, 2015 @09:41PM (#9072151)
Shared memory multi threading will still be a big barrier to porting over many native applications, like games. Unless asm.js fixes that?
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by AgentME on Thursday February 19, 2015 @12:35AM (#9072577)
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by seanmcdirmid on Thursday February 19, 2015 @01:41AM (#9072773)
Nice! I'll finally be able to implement Glitch for the web (glitch is like react but uses replay to shake out data races).
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by Fiahil on Wednesday February 18, 2015 @07:28PM (#9071798)
I share your vision. However, I think getting asm.js a good DOM access definitively coming on 2), because it's an easy way to get visual feedback from anything running in a browser.

Oh, and thanks for the very enjoyable link :)

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by woah on Wednesday February 18, 2015 @05:11PM (#9071302)
JS seems to actually be picking up a lot of speed outside the browser?
Re:Bringing asm.js to the Chakra JavaScript engine in Window... by jerf on Wednesday February 18, 2015 @06:18PM (#9071550)
First, that's not particularly relevant to the question of what happens to the browser itself. Second, the field of "things you can run that is not Javascript" when not in the browser is already incredibly rich, so we already live in a flexible world. Third, frankly I'm not particularly overwhelmed by the prospect of Javascript's longevity in the server space being a long-term phenomenon... an awful lot of what gets linked on HN is less "cool things to do with JS" and "how to deal with the problems that come up when trying to use JS on the server".

And fourthly, and why this reply is worth making, bear in mind that if the browser becomes feasibly able to run any language, rather than having Javascript occupy a privileged position by virtue of being the only language, the biggest putative advantage that Javascript-on-the-server has goes poof in a puff of smoke. If Javascript has to compete on equal footing, it really doesn't have a heck of a lot to offer; every other 1990s-style dynamically typed scripting language (Perl, Python, Ruby, etc) is far more polished by virtue of being able to be moved forward without getting two or three actively fractious browser vendors to agree on whatever the change is (just look at how slow the ES6 has been to roll out, when I'd rate to contain roughly as much change as your choice of any two 2.x Python releases). And it has no answer to the ever-growing crop of next-gen languages like Clojure or Rust. Without its impregnable foothold in the browser, Javascript's future is pretty dim. (In fact I consider the entire language catagory of "1990s-style dynamic scripting language" to be cresting right about now in general, so Javascript's going to be fighting for a slowly-but-surely ever-shrinking portion of pie.)

Re:Bringing asm.js to the Chakra JavaScript engine in Window... by reissbaker on Wednesday February 18, 2015 @08:23PM (#9071960)
Depends on how JS evolves. It got a pretty serious setback when ES4 blew up and everyone went back to the drawing board on ES5 and ES6; the ES6 launch makes it (I think) better for most use cases than Python/Ruby/et al, because the VM is an order-of-magnitude faster than most of the popular choices and ES6 is a reasonably usable language even for someone unused to Javascript's current quirks: it has a real module system, the class syntax is sane and similar to how every other lang does it, the confusing `this` binding is fixed with arrow-functions, generators and Promises get rid of deeply-nested callback chains, `let` and `const` get rid of confusing variable hoisting, etc.

Google and Microsoft are both very seriously experimenting with typed variants of JS (TypeScript from Microsoft and SoundScript from the V8 team), and Mozilla had in fact already proposed adding static typing back in the ES4 days, so I wouldn't be surprised if the next couple of versions of the ES spec include static types. The future for JS is brighter than you think — although it's brighter only because it looks like JS will become a better language, not because of JS in its current, mostly-still-ES5 state.