When did Javascript become a serious language?

Eric Wald eswald at brainshell.org
Mon Dec 9 13:23:12 MST 2013

On Mon, Dec 9, Levi Pearson wrote:
> On Sat, Dec 7, 2013 at 10:33 PM, Eric Wald <eswald at brainshell.org> wrote:
>> The good news is that asynchronous primitives are much easier to treat
>> as a synchronous system than synchronous primitives are to morph into
>> asynch systems; the latter often involves either threads or gradual
>> transitions to a duplicate API.  On the other hand, I have more respect
>> for languages that allow the asynchronous aspect to be swept under the
>> rug: Google's Go lang, for example, appears to have synchronous-looking
>> calls that transfer control back to an event loop until the result is
>> ready, while offering a simple keyword to let function calls run in the
>> background.  Of course, that requires either suspendable stack frames or
>> multiple threads, as well as an event loop.
>> Anyone care to implement that kind of behavior for Javascript?  Of
>> course, we'll need to wait for Microsoft to re-implement the new spec
>> before it can safely be used on websites...
> Numerous people have implemented that kind of behavior for Javascript,
> and there are probably still several that you can easily get for node
> via npm.  Some of them do a CPS conversion on your code, others
> implement the equivalent of a one-shot continuation-capturing
> primitive as the basis of a co-routine library.  But none of them will
> see much use in Node or browser-based Javascript programming until
> something is put into the language standard. The Node guys are highly
> against diverging the language from the same javascript that runs in
> browsers, and so there's no cultural buy-in at the library level.  And
> when your libraries are all in CPS-style, you're pretty much stuck
> building your applications that way as well.

Sounds like the same kind of split Python has with Stackless and gevent.
Guido is now implementing/promoting an asynchronous library that enables
co-routines, implemented as generators, to replace callbacks.  The
drawback to implementing this as (nearly) pure Python is that it
requires any function call that could potentially block to be prefixed
with the "yield from" keyword.  That turns the caller into a generator,
so it too must be called the same way, and so on up to the event loop.

In contrast, Stackless and gevent each modify the interpreter itself
with ways to make asynchronous code wait for an event invisibly to the
caller.  That means the API doesn't have to change when you discover
that (for example) writing to a pipe can block.

On the other hand, the "yield from" style is more portable to the other
four or five Python implementations, so the ugly way may be best.

- Eric

More information about the PLUG mailing list