< April 2005 >
SuMoTuWeThFrSa
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930
Fri, 29 Apr 2005:
The first thing a young Java programmer learns while reading through his first java book is the get/set convention. But when you look at C# you will notice that it has a properties construct (purely syntactic sugar) which enforces a few more good design rules and in general makes code cleaner. Properties in Javascript is pretty much undocumented and I've not found much documentation on this - and it is a Mozilla only hack.
function MyClass() { }

MyClass.prototype.__defineGetter__("foo", function() {
return "I am the foo";
});

MyClass.prototype.__defineSetter__("foo", function(value) {
    print(value + " is no good");
});

var a = new MyClass();
print(a.foo);
a.foo = "slashdot";
Would happily give the following output
I am the foo
slashdot is no good
The code is pretty much self-explanatory. If you don't think this is of much use, continue reading.
if(!document.all)
{

Event.prototype.__defineGetter__("offsetX", function () {
   return this.layerX;
});

Event.prototype.__defineGetter__("offsetY", function () {
   return this.layerY;
});

}
Javascript is a truly powerful language. But all graduate students try is to dig into assembly and kernel programming - leaving javascript and webdev to the lesser mortals. It's time all that changed.

posted at: 00:27 | path: /slashdot | permalink | Tags:

Tue, 26 Apr 2005:
The major problem most people have with Javascript is that there is no easy way to test your code outside the browser. Often it so happens that you might want to test out a string split or array splice quickly. Here's a quick tip on getting a python'ish javascript shell.
/usr/lib/firefox-1.0/run-mozilla.sh /usr/lib/firefox-1.0/xpcshell
This should give you something like
js> a = [42, "is" , "the" , "answer"]
42,is,the,answer
js> a.sort()
42,answer,is,the
You can run your javascript code like this and pretty much everything outside the DOM and Window stuff can be well tested. And lastly the ultimate javascript hack of all time - Object orientation.
function base() { }

base.prototype.myname = function () { return "I am base"; }

function derieved()
{
	this.base = base;
	this.base();
}

derieved.prototype = new base;

derieved.prototype.__myname = derieved.prototype.myname;

derieved.prototype.myname = function () { return "I am derieved"; }

print(new derieved().myname());
print(new derieved().__myname());

posted at: 22:03 | path: /slashdot | permalink | Tags:

Mon, 25 Apr 2005:
When look into the murky pools of the business world, you might wonder how cynical Mark Twain had to be to say "Honesty is the Best Policy - when there's money in it", because that's exactly how honesty works in the so-called modern world. It is as if the world fears that an overdose of truth can hurt and kill - which might not be far from the truth (aah !!).

What is a lie ?. Lies are not just black or white , actually they are black and white sometimes. White lies have been the real true invention in language - to communicate by not saying sometime. That's the sort of lie a lawyer says when he says "There are no reliable witnesses". And some tell the truth, but "Reality is often inaccurate".

Why do we lie: If you have seen Liar, Liar you might have realized the normal places where people lie. Society as an instituion relies on the ability of people to curb their natural instincts and say things which go against their better (or worse) nature. It is an institution built on the basis that nobody can see into your mind and the skeletons it might hold. In short, if you can't lie, decieve or pretend, you cannot survive in society. It started with the first sychopant caveman who said "Nobody makes such a warm fire like you, Ogg. And your club is huge" and it's been downhill all the way from there.

Whom do we lie to the most ?. I truthfully (ha ha !) think that we lie to ourselves the most. Self delusions of importance and ability which feeds the ego are necessary for survival. Truly depressed are those who are free from these precious illusions . Of course this attitude towards truth is mutual. When you buy a car, you don't want to hear that this model blows up once in a while - you want to hear about it's invisible anti-rust coating and push-to-start features. Truth can be brutal and offending - you don't want to be called a loser, you'd want to be called undeveloped potential. When you ask your girfriend "Do you love me ?" , you want to hear an emphatic Yes, not an "of course" or "not really". Most of us live our lives happy and content walled off by the facade of lies erected by society for our protection.

The really interesting thing about lies is that society takes a really interesting stand on it. It is as if it's ok to lie but not to get caught, which makes a lot of sense from an darwinian point of view. The differentiating factor seems to be the aspect of getting caught. But a society with a majority of absolute liars would collapse, so it maintains an equilibrium of truth and lies - or more correctly induviduals do. The threat of getting caught is the fine line that all of us walk when we lie.

In this politically correct world, the truthfully challenged seem to prosper. And an image seems to fade out in my mind - telling , no asking me - "The truth is out there". But I dare not . Do you ?.

posted at: 14:35 | path: /slashdot | permalink | Tags: