JavaScript Shell Scripting

2008
08
May

A few days ago, Peter Michaux posted a very promising article concerning xjs. I've long wanted to be able to use JS to write shell scripts (as one would do using bash, python or perl) but it lacked several important features.

Peter has added a File module which wraps Java file operations, and I see this as the first step towards taking JS out of web development. Let's face it, JS is really present in browsers, SSJS is taking off very slowly and even though a few apps use JS for scripting, it's still not mainstream.

The way I dream of JavaScript's future ? As a general purpose scripting language. This means that several things have to be done. First, an easy way of binding whatever library to JS. Second, a CPAN like repository dedicated to JS. There is absolutely no control on how would evolve the latter. The former, however, can be conceived right now.

I'm not really sure if I agree with Peter's choice of Rhino instead of SpiderMonkey, but I guess he has more experience with Java than with C — which is quite the opposite of my own misconceptions. I guess there are pros and cons for each of the choices, but I wonder if it'll be easy to port generic C libraries to JS using Rhino. I must clarify something at this point : I have a deep hatred of Java — it's a kind of zealous religion — and everything that comes near it appears like obscure magic to me.

Nevertheless, I really wish a lot of good things to xjs, and I hope that Peter will take into account the fact that an easy mechanism for porting library is a must-have.

tags

2 comments

I started xjs as a Spidermonkey implementation with dlls and the whole works for modularity. I also experimented with Rhino. It was clear that the path to a production web site was far longer with Spidermonkey than with Rhino. That is even though I prefer the ideas of C over Java and knew more C than I do Java.

The JVM is an important piece of software and is emerging as the platform of choice for implementing scripting languages. Jython, JRuby, Scala, Groovy are all JVM implementations. VMs are also being used for Rubinius and eventually for Perl 6.

The JVM and threaded Java servers, like Jetty, allow for many simultaneous requests to be fulfilled by one operating system process. This leads to the whole "Rails doesn't scale" problem as more mongrels need to be deployed to handle simultaneous request.

Don't be scared of the JVM. Yes a little Java stands in the way between the JavaScript and the JVM but the JVM is a very full-featured machine with many standard packages and zillions of JAR files on the web. If you think of something you want to do with xjs, I don't think it would take you too long to make an xjs module that does it.

I looked in detail to your source, and I must admit that having access to every Java classes and functions from JS using the java object is pretty awesome.

I'll look into all of that in details :)