Sunday 18 March 2012

CS Rage 3

Dedicated to Computer Vision Victims of our class.
Context : Exams for self-study course Computer Vision.



For the uninitiated : 

Idea Courtesy : Vijay (MVK)
P.S. :- Those of you who don't know who SRG is, the hint is 'He is to our class what SRT is to Cricket'.



Friday 9 March 2012

The Human Hero

"If I have to put anyone to bat for my life, it’ll be Kallis or Dravid". - Brian Lara

      It was summer of 2006. A 15 year old boy was in hospital. He couldn't watch the last test of India-West Indies test series there. First 3 matches had been draw. And last match was on uneven pitch of Jamaica. If India could win this match, it would be their first series victory on West Indian soil after 1971.



      The fact that Chris Gayle made a pair on his home ground is good enough to give us a picture of the pitch. It was late in a night that boy was listening to commentary, when that historical moment came. India won a test series in West Indies after 35 years, second time only in the history. For a few minutes he forgot everything about health. For some time every Indian forgot about all their problems. That victory gave that boy the strength to fight his illness.

      Rahul Dravid's career is full of such inspiring moments. Whether it is his hundred at Headingley, or his partnerships with VVS Laxman in Kolkata and Adelaide, or his fifties in Jamaica. Rahul Dravid is not God. He was never a God. He didn't have the perfection of Tendulkar or Stroke Play of Lara. He has always been a Human. And a great one.

      Where is the fun in being God? They have it easy (generally, I think). The best thing about being a human is the struggle and challenge that is the part of our very existance. And that is where Rahul Dravid teaches us the most important lesson. It's more than cricket. It's about anything we do in our life. We all have our limitations, but with a fighting attitude, we can overcome them. Thanx to Rahul Dravid for this important lesson.

      For most of his career he was overshadowed by others. His 95 on his debut at Lords was overshadowed by Ganguly's hundred. His 180 at Eden Gardens overshadowed by Laxman's 281. For most of his career his contribution to the team was overshadowed by more pleasing and attractive game of others. But he was a complete gentleman. Such small stuff never affected his personality, or his game.


"Rahul Dravid is a player who would walk on broken glass if his team asks him to" - Navjot Singh Sidhu


      An ideal selfless team player he was. He opened in test cricket when team needed him to. He took role of wicket-keeper when team needed him to do that. He was considered unfit for ODIs, the man has more than 10,000 runs in the shorter format of the game. He holds record for second fastest fifty in one-dayers for India. The man just loved challenges. There was nothing that he couldn't do.

     Of all his innings, his 233 at Adelaide is my favorite. That was Rahul Dravid at his best. What a great effort it was. With that innings he saved the match, and with his 72* in the second innings, he went on to win the match for India. The best part of that innings was the way he got his 100, by pulling Gillespie for six. And people thought only Virendra Sehwag could do that.


"All this going around is not aggression. If you want to see aggression on cricket field, look into Rahul Dravid’s eyes" - Mathew Hayden

       Apart from his performance on the field, Rahul Dravid was a perfect gentleman and great ambassador of the game. He can be counted as one of the last true gentlemen of the gentlemen's game. One of the finest batsmen of his generation. He was in the league of Tendulkar, Lara and Ponting. The best number 3 batsman in the history of Indian cricket. And as Harsha Bhogle once wrote that whenever an all time India team will be chosen, along with opening position and number 4 position, number 3 will also be already taken.

       Today when he has said good bye to the game, the game has got poorer. It won't be same without him. Indian cricket won't be same without him. The Mr. Dependable for last 16 years has left the stage empty. And on this day, that boy gives his tribute to Rahul Dravid, a true genius. Thanx for the memories. It was an honor watching you play. We'll miss you.

He is a perfect role model for youngsters. He has set a great example for all of us to follow. We are all trying to follow that path," - Sachin Tendulkar
     

Friday 2 March 2012

Inheritance in JavaScript

         JavaScript is a funny language. For a few weeks I have been reading the book "JavaScript : The Good Parts" by Douglas Crockford. This is the first time I've tried to look at javascript as more than a language just for browser. Syntactically javascript is pretty much like C, but it has much more in common with Lisp than with C. For someone familiar with languages like C and Java, it can be pretty weird at first reading.        
         One of those weird/funny things is that JavaScript has Class-free objects. There is no class hierarchy, objects inherit from objects. JavaScript provides prototypical inheritance. Every function object in javascript has prototype property whose value is an object containing a constructor property whose value is the function object.
          this.prototype = {constructor : this};
          The language attempts to provide pseudoclassical inheritance so that programmers used to the classical style don't feel bad. But in that attempt, the language has become even more complex and messy. Here is an example from the book :


        //define constructor for the pseudoclass
         var Mammal = function (name) {
                   this.name = name;
         };
         //augment its prototype
         Mammal.prototype.get_name = function ( ) {
                   return this.name;
         };
         Mammal.prototype.says = function ( ) {
                 return this.saying || '';
         };
         //we can make an instance:
         var myMammal = new Mammal('Herb the Mammal');
         var name = myMammal.get_name( ); // 'Herb the Mammal'


         //make another pseudoclass that inherits from Mammal
         var Cat = function (name) {
                this.name = name;
                this.saying = 'meow';
         };
         // Replace Cat.prototype with a new instance of Mammal
         Cat.prototype = new Mammal( );

        // Augment the new prototype with get_name method.
        Cat.prototype.get_name = function ( ) {
                return this.says( ) + ' ' + this.name +
                      ' ' + this.says( );
        };


        var myCat = new Cat('Henrietta');
        var says = myCat.says( ); // 'meow'
        var purr = myCat.purr(5); // 'r-r-r-r-r'
        var name = myCat.get_name( );
        //'meow Henrietta meow'


                So as we can see this code looks quite arbit and weird. So, instead of using this pseudoclassical complicated approach, we can try to use Prototypical inheritance as it should be used. The author has provided some good ways to get rid of this mess. One way is to define a method like following :

                Object.beget = function(o) {
                        var F = function () {};
                        F.prototype = o;
                        return new F();
                };

               Now we can just write :
              new_object = Object.beget(old_object);


       And then we can make changes to the new object without affecting the old one. This is called differential inheritance.


        In all these techniques, there is something quite important that  we haven't yet paid attention to. That is the idea of encapsulation. Here we use closures fundaes. Let's revisit the cat and mammal example : 
          




       var mammal = function (spec) {
            var that = {};
            that.get_name = function ( ) {
                return spec.name;
            };

            that.says = function ( ) {
                return spec.saying || '';
            };
            return that;
       };
       var myMammal = mammal({name: 'Herb'});

       var cat = function (spec) {
           spec.saying = spec.saying || 'meow';
           var that = mammal(spec);
           that.purr = function (n) {
               var i, s = '';
               for (i = 0; i < n; i += 1) {
                   if (s) {
                       s += '-';
                   }
                   s += 'r';
               }
               return s;
           };
           that.get_name = function ( ) {
               return that.says( ) + ' ' + spec.name +
                    ' ' + that.says( );
            }
            return that;
       };
       var myCat = cat({name: 'Henrietta'});


             I've given brief description here. If someone wants more details, they can visit
             http://www.crockford.com/javascript/inheritance.html
             http://javascript.crockford.com/prototypal.html