JavaScript

All posts tagged JavaScript

I really enjoy learning new things in the field of computer science.  Recently I have been learning some new computer languages and having a great time into the bargain.  Ruby is my favourite, but I’ve also started playing with node.js which is an asynchronous IO library bundled with an implementation of JavaScript (or ECMAscript) because substack has been Plurking about how wonderful it is.  I’m not all that keen on JavaScript so far, partly because I’m so keen on Ruby and partly because of the criticism of it by Douglas Crockford in his book JavaScript: The Good Parts.  However he is not totally anti-JavaScript and has spent a lot of time working on its standardisation as described in a YUI Theatre video called The State and Future of JavaScript.  (This was very interesting for me, for reasons some people may know, though of course I didn’t agree with everything he said.)  There’s a bunch of intriguing talks available at The YUI Theater which I’d love to watch.  I did watch the one by Ryan Dahl on node.js and I expect I will go back for more.

The computer on my desk at home runs Windows (XP SP3 at the moment) rather than my beloved NetBSD or a Linux variant.  Of course my servers run real OSes, but I wanted to work on my desktop machine and so spent a while installing node.js, its package manager and associated packages under Cygwin, which is what makes programming on a Windows machine bearable for me.  The node.js installation instructions cover Cygwin separately and the instructions there worked for me.  However I had a problem using the Node.js Package Manager to install third-party modules.  As described in this email thread, Cygwin pipelines into gzip can hang in certain environments.  I spent hours rebooting, reinstalling and futzing around until I found that thread, which goes on to lay the blame on a “BLODA“.  It turns out that certain antivirus applications can cause this, by hooking themselves into the system call invocation chain in a way which doesn’t actually work perfectly.  I turned my AVG Antivirus Free (v11) off for 30 seconds during the installation of this particular package (called “request“) and the installation went like a dream.

Node.js is young software and under frenetic development.  One promising use-case is the implementation of very scalable web applications, where the asynchronous IO model can yield great efficiencies.  My interest in it is as a web client, where I hope to use it to retrieve and execute JavaScript from websites whose applications depend on it, but with which I want to interact with programatically rather than manually in a browser.  Some such websites (for example Plurk) provide proper APIs for this, whereas others, such as Facebook, do not.  Facebook requires you to write a Facebook application instead.

A consequence of node.js’s youth is the immaturity of adjunct libraries for interaction with other services.  Although HTTP is treated as a first-class application with built-in support, that support is primitive at this stage when compared with Ruby’s net/http.  I’ve been exploring the available libraries for node, which for HTTP client applications include node-httpclient, node-get, node-http-digest, request and abstract-http-request of which the last two look particularly promising.  None of them appear to offer cookie storage between requests, which is something I will need.  At the moment I’m thinking of using one of the available key-value storage libraries which are available to store cookies.

Once one receives the appropriate page from the server, the HTML may need parsing (and there are plenty of HTML parsers for node, such as this), and scripts therein will need executing (aha! That’s why I’m using JavaScript to write the program!).  That’s all in the future.  For now, I’m able to run simple JavaScript programs which fetch pages from websites, and ready to start the real work.