inicio mail me! sindicaci;ón

The JavaScript Bandwagon

A few month’s ago, i decided to hop on the Javascript bandwagon. I wanted to find out what it could do, how well it could do it, and what limitations i would bump into.

What i discovered was not what i expected.

Incompatibility

First and foremost, one of the first problems one bump’s into with javascript is that all the major web browsers implement it differently. Code can work perfectly in one browser and fail miserably in another. For example:


var myList = {
tea: 1,
coffee: 2,
};

Seems perfectly fine to me. In fact, it worked fine in Firefox. However, it didn’t work in Safari, Apple’s flagship browser. The only clue in the JavaScript console i got was “SyntaxError – parse error”, which eventually led me to this solution:


var myList = {
tea: 1,
coffee: 2
};

Yes that’s right… all that fuss was over a single little comma.

Simple? Not!

After figuring that Javascript was a pretty simple c-style programming language, i thought i had it all figured out.

However, after checking out Dogulas Crockford’s presentation “The JavaScript Programming Language“, i was left a bit dumbfounded. What i thought was a simple boring run-of-the-mill scripting language was in fact a pretty extensible and interesting programming language. Neat!

Frameworks

The first time i tried writing something in JavaScript, i decided to go “all-pro” and not use any of the numerous development frameworks that have popped up over the years. This was a big mistake.

After a long period of writing everything from scratch (whilst only half knowing what on earth i was doing i might add), i stumbled across the mootools framework.

Selecting elements? simple. Handling events? simple. Making complex object-oriented front-end’s? simple. Having it all work in every major web browser? priceless. In fact, pretty much everything was ten times easier to work with, and solutions took less than half the time to be implemented.

Slow, yet fast, yet slow

Sadly, since JavaScript does not have a single implementation, performance varies a lot between browsers. For simple things, the difference was hardly noticeable. For more complex things though (e.g. interfacing with the WhatWG canvas), differences definitely became much more noticeable, although i would not like to speculate which browser has the fastest implementation of JavaScript as i have not done any conclusive benchmarks yet.

Single Threaded

Sadly for the most part, there is no support for threading in JavaScript. You can only do one thing at once. Whilst this is not a bad idea, it does become a little bit of a problem if you are running multiple time-out’s and intervals. Everything has to wait for its turn in line so to speak, which is pretty much bad news if you really want something to happen in X amount of time, irrespective of whatever else happens in-between…

…oh well, i guess i can live with it.

Safe to say, i’ll be experimenting a bit more with JavaScript in the future.

  • Gaz
    Hi James,

    I must admit that I've avoided learning javascript for several years, mostly because I always thought it was a hacky means of fiddling with the DOM of rendered pages on the fly (woo hoo!), and more recently because AJAX and JSON scare the hell out of me from a security point of view.

    I'll be interested in what else you have to say about it as you get deeper into the language, and maybe change my mind over whether it is worth spending the time for me to learn it...

    Cheers,
    Gary
  • Gary,

    The power of JavaScript has certainly become more evident over the years, especially if you take into account how sophisticated webmail services have become (e.g. zimbra).
    Sad to say though, as you mentioned AJAX and JSON are more or less security nightmares, although i suspect that is mainly because developers aren't security minded in general when dealing with javascript requests (e.g. exec'ing JSON instead of parsing it). There are also still too many unknown's with regards to security in the actual browser (e.g. bookmarklets are inherently insecure).

    I think its worth learning JavaScript if you are also thinking about developing Flash-based apps (e.g. using FLEX), as the scripting language that uses (i.e. ActionScript) is more or less based on ECMAScript, otherwise known as JavaScript.
blog comments powered by Disqus