Archive for September, 2006

* No Movies on Oil Rigs?

Posted on September 28th, 2006 by Dave Johnson. Filed under Copyright, Fun.


I actually read, for the first time, the copyright warning at the begining of a movie when I watched a bit of Fight Club for the umpteenth time late last night. Apparently they don’t want people watching movies that have been purchased for home use in places like prisons or oil rigs! Seems like a bizarre choice of examples of unlawful use. I mean how many people do you know out on oil rigs? Even more importantly how likely is 20th Century Fox going to try and stop some oil men from watching the Hollywood hit when it comes out on DVD. And remember, no lending your Fight Club DVD to you friends!

copyright

Tags: .



* The Amazing $5000 Podcast

Posted on September 15th, 2006 by Dave Johnson. Filed under AJAX, Business, Fun, Podcast, Redmonk.


Interesting email came in this morning. The OpenAjax alliance had been invited (to our greatest surprise and dismay) to take part in a podcast series about Ajax with the analyst firm ZapThink. At first thought it seems very reasonable. However, when you actually read the small print (ok it wasn’t that small) they wanted people to pay $5000 for the chance to talk on their podcast! Of course they are gracious enough to give people referred by IBM - who are a driving force behind OpenAjax - a whopping $1000 discount. Well sign me up!

They try to sell the idea to us by saying that they have literally _hundreds_ of downloads per podcast! I mean come on. Even the no good useless pukes that are Dave, Andre and Alexei were able to quickly pass the century download mark with our little audio recording about Ajax.

The real icing on the cake comes when they try to justify the price by saying:

There is a cost involved - in part to defray the costs of producing and distributing the podcast, and in part because as sponsors they get marketing visibility and leads.

Oh that’s right - the large costs associated with podcasting like that $29.95 for the headset and maybe some sort of opensource recording software. If it weren’t for the high cost I am sure that more people would be flocking to podcasts … It reminds me of the talk we had with ZapThink a while back. No wonder so many people are happy to talk to Redmonk. The greatest part about them is that we did a podcast with Cote (granted it was the podcast from hell) and we didn’t have to pay with anything but our time!

I think we will try charging the next people that come on our podcast ;)

technorati tags:ajax, podcast, redmonk, zapthink

.



* Grid V3.2 - Just One More Day

Posted on September 14th, 2006 by Dave Johnson. Filed under Business, Grid, Web.


We have been up all night but to no avail - Alexei is gone home dreary eyed and even Andre has headed back to Squamish.

James and I will be here for a little while still as we push to get the release out before the weekend.

Stay tuned.

.



* Holy Memory Leak Batman!

Posted on September 11th, 2006 by Dave Johnson. Filed under AJAX, Flickr, Memory, Performance.


Not sure why I am on this Batman kick but I just checked out Flickr for memory leaks in preparation for my talk at AjaxWorld in October and it is just crazy. The image speaks for itself. Just loading and re-loading a picture details page on Flickr seems to have massive memory problems for IE based on the Drip tool. Click the image below to see the enitre story in all its drippy goodness.

flickr memory

.



* Grid V3.2

Posted on September 10th, 2006 by Dave Johnson. Filed under AJAX, Components, Grid, Nitobi.


It’s 10:30 on saturday night and I am just finishing up another pass over the documentation for Grid V3.2 which we are planning on launching this thursday (sept 14th). It is looking like a not _so_ unrealistic deadline. I am looking forward to getting the new JSDocs out there and hearing some feedback as the current docs are admitedly sparse at best. This time around the docs will not only be better but the Grid will have far better support for runtime manipulation and local data sources. Andre, Alexei and I took 30 minutes today to do a quick podcast as well that should be up tomorrow I guess.

It’s time for a drink. Hope everyone is having a good weekend!

.



* links for 2006-09-08

Posted on September 7th, 2006 by Dave Johnson. Filed under Uncategorized.


  • Good post about javascript inheritance (btw it’s mine)
    (tags: inheritance javascript ajax web20 web2.0 oop benchmark performance)

.



* On Classical JavaScript Inheritance

Posted on September 7th, 2006 by Dave Johnson. Filed under AJAX, Benchmark, JavaScript, OOP, Performance, Web.


Ok, I have been a little busy lately (well really busy) but this post has been in the works for a few weeks now so I just want to get it out.

First off, of the half dozen or so requirements that Dean Edwards puts on his Base.js implementation I admittedly only agree with two of them - and you should see why at the end of this post. Those two are:

I want to avoid calling a class’ constructor function during the prototyping phase
I want to achieve the above without affecting Object.prototype

Those are by far the most important points - particular number one since when dealing with the DOM / UI we don’t want things to happen pre-maturely.

Anyway, the reason for this post is actually due to a recent post on Ajaxian about JavaScript inheritance that was interesting to say the least. It reviewed a few different techniques of performing classical inheritance in the prototype base language that is JavaScript. It reviewed simple inheritance using the syntax like

SubClass.prototype = new BaseClass();

where super methods can be called using global references to the BaseClass from the SubClass and call or apply such as

BaseClass.prototype.getName.call(this);

The author also looked at the more advanced technique from Douglas Crockford and finally showed his preferred method.

There are a few points that I would like to add to the discussion. First of all, the authour suggests staying away from syntax such as

function BaseClass() {
  this.getName = function() {
    return "BaseClass";
  };
}

due to the fact that it can cause “SEVERE” memory leaks in Internet Explorer. Closures - which is what is used here - are one of the most useful features of JavaScript and should not be avoided but instead embraced. Indeed, if you lose references to DOM elements in your closures without removing them you can get memory leaks. Whether or not the leak is severe depends on how much memory is taken up by your DOM references of course. Just because something is dangerous does not mean it should be avoided - I am not going to stop drinking scotch any time soon ;)
I also thought that the example he gave to show how the Crockford method is broken was a bit strange. Admittedly, it does seem that the alert from the Crockford method is not correct being (2-1-1), however, I don’t think that the alert from the authors code is correct either. The numbers I would expect to see would be (2-2-1). In fact, with no polymorphism, overrides or other method metadata, who is to really say how it should work?

There were also two very important inheritance techniques that I thought should have certainly been mentioned. One important technique is that developed by Dean Edwards, which _very_ nicely emulates the usage of the super keyword in Java (although he uses base since super is reserved) to provide access to the BaseClass. If you are interested in the Dean Edwards code go check out his blog. The other is the use of global references that refer not to the BaseClass, as the authour showed in his article, but instead to the SubClass; thus, we avoid any problems one may have with making explicit references to the BaseClass within the SubClass code. We can define a global function that extends a SubClass that looks something like this:


/**
* Allows support for inheritance.
* @param subClass {object} The class that will inherit from the base.
* @param baseClass {object} The class that will be inherited from.
*/
nitobi.extend = function(subClass, baseClass)
{
  // Create a new class that has an empty constructor
  // with the members of the baseClass
  function inheritance() {};
  inheritance.prototype = baseClass.prototype;
  // set prototype to new instance of baseClass
  // _without_ the constructor
  subClass.prototype = new inheritance();
  subClass.prototype.constructor = subClass;
  subClass.baseConstructor = baseClass;
  // enable multiple inheritance
  if (baseClass.base)
  {
    baseClass.prototype.base = baseClass.base;
  }
  subClass.base = baseClass.prototype;
}

This is similar to the method over on Kevlindev. Btw, discussion about all of these techniques can be found before the Crockford technique when Googling for “JavaScript inheritance”. I digress. We have also added the prototype chain support for the base keyword. This type of inheritance has met all our needs and enables multiple inheritance by providing global references to the BaseClass through the SubClass itself as well as to the base constructor. To use it one would write something such as this:

SubClass = function() {}
nitobi.extend(SubClass, BaseClass);

Methods in the BaseClass are then called like this:

SubClass.base.someMethod.apply(this, arguments);

Not only is this, IMHO, a clearer syntax than something more esoteric like “arguments.callee.$” but it also has the added advantage of being faster - as I will show in a moment - than something more complicated like being able to use the word “base” directly. Furthermore, by using the Prototype library syntax for defining functions where the prototype of an object is set to an inline object itself such as:

var myClass.prototype = Class.extend({
  someMethod: function() {},
  someProperty: 5
});

it makes it much more difficult to document using tools such as JSDoc. I always find myself missing commas too! Personally, I find the Prototype syntax much more unfriendly, although it is slightly more terse.

As for the performance, just to give an idea of how the different techniques fair I made a simple animal inheritance chain and checked that the inheritance works properly using each method and then measured 1000 class definitions and instantiations with a call to the super / base in the constructors. It was some nonsense like this:

function Animal(name) {
  this.name = name;
};
Animal.prototype.name = "";
Animal.prototype.eat = function() {
  this.say("Yum!");
};
Animal.prototype.say = function(message) {
  alert(this.name + ": " + message);
};
function Cat()
{
  Cat.baseConstructor.call(this, 'cat');
}
nitobi.extend(Cat, Animal);
Cat.prototype.eat = function(food) {
  if (food instanceof Mouse) Cat.base.eat.call(this);
  else this.say("Yuk! I only eat mice - not " + food.name);
};
function Lion()
{
  Lion.baseConstructor.call(this, 'lion');
}
nitobi.extend(Lion, Cat);

Here is what I found for performance using various techniques:

Internet Explorer

Approach Time Relative
Nitobi 320 1
Crockford 340 1.06
ThinWire 580 1.81
Edwards 1360 4.25

Firefox

Approach Time (ms) Relative
Nitobi 360 1
Crockford 460 1.27
ThinWire 2300 6.39
Edwards 3600 10

I was pretty surprised at the horrible performance of the Edwards base.js in Firefox! At any rate, something to consider for those that do things because they want JavaScript to be more like Java ;)

technorati tags:ajax, javascript, performance, benchmark, inheritance, oop

.



* Nitobi Grid Launch Date

Posted on September 7th, 2006 by Dave Johnson. Filed under AJAX, Business, Declarative Programming, Grid.


Ok so we have set a date of Sept 14 for launching the latest version of our Grid control. Given some quality control issues in the last release we are trying to tighten her down and get her ready to work nicely with our framework. Best of all the docs will be kick ass ;)
Once we launch then I can get my GMaps mashup online too!

.



* Nitobi Podcast #12

Posted on September 1st, 2006 by Dave Johnson. Filed under AJAX, JavaScript, Podcast, Web2.0.


Just what everyone has been waiting for - no not the release of Snakes on a Plane - Nitobi podcast #12! Since we have been so busy, we had to skip last weeks episode but we won’t let it happen again. We talked about a few things such as the fun time we had at BarCamp Vancouver, various online apps, and my latest antics with finding food in dumpsters. Get it while it’s hot!

If you haven’t already, then pick up the feed here.

Oh yeah, and thanks for the props on the music Michael - I had to push hard to make that happen ;)

.