If a million monkeys were to type on a million typewriters, would one of them produce Hamlet? That’s the boring question. The intresting one is what would they produce the rest of the time…
RSS icon Email icon Home icon
  • WTF moment- Extra Special

    Posted on May 13th, 2009 silverback No comments

    From: silverhairedbaboon@sales.justatechcompany.com

    To: technicalperson@gmail.com

    Technical Person,

    Congragulations!! I have just come to know from Silverback that you have quit our lovely organization and have decided to move onto another lovely organization. Which is wonderful. The “other lovely” organization is really brilliant and is quite differentiated. In fact the CEO of the “other lovely” organization quit our organization and joined their organization some six months back. So quite differentiated indeed. Though I think differentiated is not the word I need right now. Btw! I realize you have quit, changed your cellphone number, switched off your previous cell and moved to a different city all to avoid what you describe as this “total lack of concern for my personal life”, but I was wondering? Would it be possible for you to join a solution presentation call for a customer from 11.00 p.m. your time to 2.00 a.m. your time on Wednesday? Just asking. Do confirm.

    Regards,

    Silver Haired Baboon

  • Watchmen: The movies

    Posted on April 26th, 2009 silverback No comments

    Not so good. The book is like a tapestry. There are so many individual threads that make up the story of the watchmen. The thread with the sailor. The thread with the boy reading the sailor comic. The thread with the psychologist. The thread with the original Nite Owl. All of them make the Watchmen comic. The book is more than the sum of its parts, yet what you remember of the book are its parts, which hold your attention long enough, and have you panting for more even after you have turned the last page and put the book back onto the shelf. The movie is bland. It moves forward linearly, which is asinine at least for an adaptation of the watchmen. Overall a 2 out of 5.

  • A hiatus

    Posted on July 28th, 2008 silverback 1 comment

    Was working on some side projects to try and pickup a little extra moolah. I need it if I hope to buy my very own first laptop. All my other computing devices have been sponsored to a large extent by my dad, so here’s wishing for my very own one.

    P.S.: This way I won’t have to listen to the wife grumble about me spoiling her laptop.

  • Bugger!!!

    Posted on July 3rd, 2008 silverback No comments

    No net connection for a couple of days, so couldn’t update the blog. Looked at it sunday only to find out that znetindia had let the server that was hosting my home directory go down. Bugger! The blog couldn’t be accessed, and nothing else. In a panic, I deleted my original database, only to find out later from znetindia that the server had only gone down. Oh! and they don’t provide shell access. Finally after a lot of work back up today. Stick with me. I have a couple of ideas for a couple of books that  I think I would start writing soon…

  • Lessons in Language Design III

    Posted on July 3rd, 2008 silverback No comments

    Consider a class written in Ruby.

    class Sandwich
    def  initialize(type_of,rate)
    @type_of=type_of
    @rate=rate
    end
     
    def print_details
    print "A #{@type_of} sandwich costs #{@rate}  Rs."
    end
    end

    Brilliant!!! So here you have a simple class that can make a new person who has a name and print the person’s name.

    1
    2
    
    s=Sandwich.new("Vegetable",30)
    p.print_name

    And the answer unsurprisingly is:

    A Vegetable sandwich costs 30  Rs.

    Now consider returning change. The amount of change you get for a 100 depends on the kind of sandwich you got. A vegetable sandwich will net you 70 Rs. change while a chicken sandwich should get you 50 Rs. (the chicken sandwich costs you 50 bucks). So if you were to write it in code…

    class Sandwich
    def  calculate_change(amount)
    change=amount-@rate
    end
    end
    c=Sandwich.new("Chicken",50)
    print  s.calculate_change(100)
    print c.calculate_change(100)

    And the answer unsurprisingly is:

    70
    50

    Now consider a closure. A closure is an intermediate point of time between defining a function and calling it when on or more arguments have been fixed but the others haven’t.  For every language there are two phases when you call a function. Then function definition where the parameters of the function are defined and then there is a binding phase when the actual arguments are bound to the function. Errmm… Consider the following function:

    def  print_stuff(x)
    print "Hello"+x
    end

    Now print_stuff takes a parameter x. When the function is first defined then it’s a function that has a single parameter named x. Later when you call the function like this

    print_stuff  ("World")

    then the compiler/interpreter binds the value of x to "World", which is another way of saying that it makes print_stuff believe that x is "World". The act of binding of course raises a few questions:

    • When does x start to be “World”
    • When does x cease to be “World”
    • If x had been defined previous to the function call to be 123 then what happens when the function ends

    There can be different answers to these questions, and each leads to a particular flavour of implementation and hence to a particular feature of a language. Now a closure is a particular function that has bound one of it’s parameters to a specific value while the other parameters can be modified. Consider the following function:

    def  calculate_change_for_vegetable_sandwich
    return Proc.new{|amount|  amount-30}
    end

    So calculate_change_for_a_vegetable_sandwich gives you a function that takes a parameter which is the amount you pay and returns back the amount -30. You could create a similiar function for chicken sandwiches…

    def  calculate_change_for_chicken_sandwich
    Proc.new{|amount|  amount-50}
    end

    and call these two functions like this:

    change_for_chicken=calculate_change_for_chicken_sandwich();
    change_for_vegetable_sandwich=calculate_change_for_vegetable_sandwich();
    change_for_chicken.call(100);
    change_for_vegetable_sandwich.call(200);

    and not unsurprisingly the answers are:

    50
    170.

    Now can you generalize the calculate_change_method?

    Of course you can. Here’s how:

    def  caluclate_change(price)
    Proc.new{|amount| amount-price}
    end
     
    calculate_change_for_chicken=calculate_change(50);

    Which means that the calculate_change method takes the price as 50. Binds price to 50 in the function created inside it and returns it. WooHoo!!!

    Now let’s see if we can generalize it further still….

    def  make_Sandwich(type,rate)
    self=[]
    self[0]=type
    self[1]=rate
    self[2]=Proc.new{print  "A #{self[0]} sandwich costs #{self[1]} Rs\n"}
    self[3]=Proc.new{|amount|  amount-self[1]}
    return self
    end

    So now you could do:

    s=Sandwich.create("Vegetable",30)
    s[3].call(100)

    Can you see the similarities with a class. In fact a class is basically syntactic sugar for being able to say s.calculate_change(100) instead of s[3].call(100). Which brings me to the epiphany of the day. All that C++ did over C was to introduce closures to the language and the syntactic sugar to enable classes. Which is also why people who program in lisp laugh when you talk to them about OOPS. They already have it and they seem bewildered that any language language took so much time to implement something so simple could be so widely esteemed. It seems a little stupid as it indeed is.

    A class for those intrested in linguistics seems to do to the language what pronouns do. It makes a handy reference to the object in discussion, while at a meta-level you can talk about the properties of all instances which satisfy the conditions necessary to belong to a class. Sheer luck in naming a feature, but a class does seem to very closely satisfy the dictionary meaning of class.