JavaScript, not only for client-side web-fu

| | Comments (0) | TrackBacks (0)
To be honest I think JavaScript deserves a lot more credit than it has. Yes - browsers occasionally crash because of it and eat up all your CPU for breakfast but don't blame the language for that - blame the runtime(s). People often associate JavaScript with Java despite the fact they have nothing in common. The naming is purely PR and was conceived at a time where JavaScript was supposed to bridge Java-applets and HTML pages.

Back in 2001 at my old job I was working on a content management system where all entities on the pages were represented as objects and stored in an object-database that we had developed. The database server was developed in Perl and supported a kind of triggers when objects were created, update, deleted etc. Since the CMS targeted web we felt that most developers who would built sites in our system would be more likely to know JavaScript than Perl. Thus I developed a Perl/JavaScript bridge that we released as open-source and I still actively maintain. It links to SpiderMonkey which is the original JavaScript engine by Brendan Eich and that is still used in Firefox. 

Now, what's it that so awesome about JavaScript you might ask?

Not very much built-in
At its core JavaScript doesn't contain very much - there's a few built-in classes to do common things with dates, string etc but there's no IO, no low-level interfacing to the system, no databases. All this has to be provided by the host which makes it an excellent language to use an extension language.

Simple unified syntax
The syntax resembles a lot of C and Java which makes it easy for novice programmers to pick it up. 

For example, say we want to iterate over the contents of an array and print out the results using our print function (which we've supplied the runtime):

function do_something(array) {
  for (var i in array) {
    print(i + " : " + array[i]);
  }
}

Now, the same for-in syntax is used to iterate over the properties of an object and we can address properties in objects using brackets so without change we could pass it an object and we would print key/value pairs instead of index/value.

Almost everything is an object
With a few exceptions everything is an object in JavaScript. You can pass around a function just as any other object which makes dynamic programming very easy.

Dynamic weak typing
There's no need to declare what kind of data your variable will hold nor does it have to stay the same over the lifetime of your script. This means that we can focus on the behavior rather the relations of things.

Regular expressions
One of Perls best features is it's strong support for regular expressions. JavaScripts' support is almost as strong and invaluable when working with validation of external data.


0 TrackBacks

Listed below are links to blogs that reference this entry: JavaScript, not only for client-side web-fu.

TrackBack URL for this entry: http://blog.versed.se/cgi-bin/mt/mt-tb.cgi/4

Leave a comment

About this Entry

This page contains a single entry by Claes Jakobsson published on May 7, 2008 7:55 PM.

Tools of the trade was the previous entry in this blog.

Transliterate in JavaScript is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.