Thursday, June 1st, 2006

Narrative JavaScript: Async blocking for JS

Category: JavaScript, Library

Neil Mix has created an extension to JavaScript called Narrative JS:

Overview

Narrative JavaScript is a small extension to the JavaScript language that enables blocking capabilities for asynchronous operations. This makes writing asynchronous code sequences easier and increases code readability.

How it Works

Narrative JavaScript consists of a compiler and a runtime library. You write your code code as Narrative JavaScript (using the blocking operator) and the compiler will parse and translate the code into regular (asynchronous) JavaScript. You then deploy the compiled code along with a runtime library. To aid in debugging, the compiler keeps line numbering of the source code intact in the compiled code.

Do we need this abstraction to make async simpler?

Posted by Dion Almaer at 8:44 am
10 Comments

++++-
4 rating from 27 votes

10 Comments »

Comments feed TrackBack URI

“After years of writing and debugging mind-warping, impossibly complicated asynchronous client-side “AJAX” applications, Narrative JavaScript was created to ease the pain inherent in writing large-scale applications using callbacks.”

Crikey – I dont think Ajax is complex at all! Its just another method of serving http content… Mind you anyone can make things complex ;) I think Narrative looks complex compared to unobtrusively adding Ajax functionality based on html / css content..

Comment by Ross — June 1, 2006

I discovered a similar method of simulating preemption using a similar construct of splitting a single function up into logically distinct parts and branching to different points in the code when the function is “resumed” (called again) (from a terse reading of the examples, this appears to be what it does). But I found this to be diminishing returns — it became a reason to NOT actually learn and use the javascript-specific/ajax-specific language/features because using something like this I assumed I could leverage what I already knew from other languages and could write javascript code that looked like and operated like languages I already had experience with.

I think the payoff might be larger if one was to just bite the bullet and learn to think about their problem in ajax/javascript and actually write it using that, rather than trying to bolt on features from other languages to make it “easier” to do something in javascript.

(by the way, there should be a way to toggle the live preview of the comments in this comment form, because it can be god awful slow — it seems to cause some page reflow with the graphics/ads on the right (at least in FF1.0.7, which I happen to be using right now)

Comment by Andy — June 1, 2006

I say: yes, we do, but only for large, single-page applications. No need to over-engineer the more lightweight uses of Ajax.
Thanks for the post.

Comment by Neil Mix — June 1, 2006

[…] (Update: Narrative JavaScript is on Ajaxian now, too.) […]

Pingback by Neil Mix » Blog Archive » Narrative JavaScript in the News — June 1, 2006

Understanding closures makes this kind of thing unnecessary. If you provide a closure as callback to an asyncronous call, that closure can act as a logical continuation of the execution of the calling function.

Comment by Theo — June 1, 2006

The callback style (closure or no) is what NJS sidesteps. I’ve watched the nuevo-JS-elites fumble for browser closures for the past year. Neil nailed it (excepting use from inside try/catch or switch/case) in under three months from his first blog post. Some may not need the power and elegance that this delivers, but this isn’t a minor development.

Comment by Bright Fulton — June 1, 2006

I’ll second Neil Mix’ comment.

If you understand closures it becomes trivial to generate long strings of functions as event handlers that act in logical sequences.

And anyway, the A in AJAX stands for Asynchronous. It’s there for a reason. Spend some time grokking this and you’ll get a lot farther with Javascript. It’s really not that complex.

Comment by Michiel — June 2, 2006

[…] Narrative JavaScript: Async blocking for JS: “Neil Mix has created an extension to JavaScript called Narrative JS: Overview […]

Pingback by Narrative JavaScript: Async blocking for JS — June 5, 2006

See more information on Javascript blocking parallel content download http://www.artzstudio.com/2008/07/beating-blocking-javascript-asynchronous-js/

Comment by phpdude — April 2, 2009

Also explained here also http://www.webdigi.co.uk/blog/2009/avoid-javascript-blocking-content-download-on-your-website-during-page-load/

Comment by phpdude — April 2, 2009

Leave a comment

You must be logged in to post a comment.