News for hackers. Stuff that matters.
Re:Stratified JavaScript by stephenjudkins on Thursday April 29, 2010 @05:07PM (#1306051)
This is a neat project. It would be great if there was a better explanation of how it actually works. From glancing at the code, here's an example of what it appears to do:

It transforms this:

  doSomething();
  hold(timeInMs);
  doSomethingElse();
Into this:

  doSomething();
  setTimeout(function() {
    doSomethingElse();
  }, timeInMs);
Basically, it uses code transformation to transform "synchronous" code into "asynchronous", callback-based code. The previous example isn't too bad, but if one starts adding many more callbacks, code can quickly become much more unreasonable. Worse still, it gets painful to refactor synchronous code into asynchronous code and back. Stratified JavaScript attempts to handle this slow, largely mechanical work for you.

It's not actually this simple, though--the javascript is actually compiled down to a representation that is executed by the Oni (http://www.croczilla.com/oni) runtime.

It also appears to allow one to "suspend" code at the callback breaks, passing it around as a continuation and resuming when required.

I would say this effort is broadly similar to the delimited continuations support in Scala 2.8. See http://www.scala-lang.org/node/2096.

Re:Stratified JavaScript by afri on Friday April 30, 2010 @03:25AM (#1307489)
Delimited continuations look interesting. I'd be curious if you could implement something like SJS's ALT operator ('@') with them:

A@B follows both branches A and B simultaneously and, as soon as either one of them returns, it cancels the other one. Cancellation means that the 'losing' branch gets a chance at cleaning up after itself (close sockets, remove ui, etc) and then gets abandoned.

(Disclaimer: I work on SJS)

Re:Stratified JavaScript by tolmasky on Thursday April 29, 2010 @03:41PM (#1305727)
This project has been around for a while, and I've always found it really interesting. I wish more people were working on approaches like this to make asynchronous programming easier on the developer.
Re:Stratified JavaScript by jackfoxy on Thursday April 29, 2010 @03:50PM (#1305761)
Can you give a quick run down on why I should be interested? I gave it the standard "very quick look" and didn't make any headway.
Re:Stratified JavaScript by shib71 on Thursday April 29, 2010 @04:53PM (#1306000)
It's a javascript extension. i.e. you write javascript in a:

    <script type="text/sjs"> ... </script>
block, which is parsed and compiled into native javascript. It allows you to write asynchronous javascript using straight forward syntax. e.g. pause execution (hold), split code into parallel tasks, split code and automatically join when one branch finishes (function @ function - think search), and suspend/resume code using events.

It's very cool and now I'm going to start looking for an excuse to use it.

Re:Stratified JavaScript by jackfoxy on Thursday April 29, 2010 @08:35PM (#1306686)
Thanks. I get it. From your short description sounds like more human overhead involved in planning how to do it as opposed to using worker threads (not available in IE yet).
Re:Stratified JavaScript by apphacker on Thursday April 29, 2010 @04:39PM (#1305954)
I wish it discussed more about how it works. I looked over that page and the Oni site and without downloading the code and looking at it I didn't see any way to understand what it is actually doing.