Saturday, February 27, 2010

I am an Exception .....

Sunday afternoons are slow,calm,quite and peaceful. I usually like to spend my sunday afternoon at my favorite coffee shop sipping my favorite cold coffee(cappe nirvana),sitting beside the window watching time fly slowly.

On last sunday something unusual happened …. a couple in the coffee shop suddenly started arguing with the waiter for bringing the wrong order(to be honest poor waiter was not at fault,they placed the wrong order).As situation was about to get tensed ,suddenly cafe manager came into the picture from nowhere,listened to the argument patiently and handled the situation in a very diplomatic manner. This situation could have grown worse and it might have resulted in the feeling of sickness among the other customers also and they might have walked out disrupting the normal flow of business and afternoon also, but the situation handled by the cafe manager was remarkable.

Suddenly I realized that cafe is also a sequence of predefined actions(taking order,serving order,billing etc.),in other word it is also a program,and an exception occurred which was handled appropriately avoiding untoward situation. In the smooth flow of the cafe business suddenly the wrongly place order was about to break the flow,this event was similar to the “Exception ” in the programming.

Exception is shorthand for the “Exceptional Event” or in other words is the event that disrupts the normal flow of the program.
Whenever an exceptional event occurs within the method ,the method creates an object (which is called as Exception object )of it and hand it over to the runtime system ,this process is known as “throwing an Exception”.(In above scenario method was to placeOrder and exceptional event was wrong order)

The runtime system will try to find something to handle this exception object, in the Call stack, Call Stack as the name is the ordered list of all the methods that had been called ,in reverse order ,to get the method where exception occurred.
The runtime system actually looks for the Exception handler which is a method in the call stack that contains the block of code to handle the exception .(cafe manager played the runtime system and looking for the solution for the unexpected situation was similar to looking for call stack for the handler)

When an appropriate exception is found (by appropriate exception I mean if the type of the exception object thrown matches the type that can be handled by the handler.) runtime passes the exception to the handler. The exception handler is said to catch the exception.(when the manager handled the situation completely)

If the runtime exhaustively searches for the handler and if it doesn't find one one then comes the nightmare of any developer ….the flow terminates.

Exceptions are not the crime or something which is unforgivable but is some unexpected situation occurred which have caused the normal flow to disrupt.

So I have started behaving like a cool cafe manager. whenever I find an exception I coolly go to the method where exception occurred and say “hey how may I help you ?” and put my exception handling solution around it .


Friday, February 19, 2010

I don't know what is programming............


After spending a couple of years as a hardcore programmer , I have realized that I don't know what
is programming or I can say that I have been doing programming since the day I was born .
While I was programming a new chat system, I observed that I have been missed out something for  so many years of programming.There lies a striking similarity between programming and day to day life.

Life is a series of the sequences woven together logically and programming is no different. It may because of the educational culture of India that I couldnt observe such a beautiful similarity before .

Lets take an example when we ask someone “what's your program dude?” or we when say to bunch of our friends”lets set the program”. Or when we turn on the idiot box runs a list of coming up programs, it means a sequence of predefined actions.

Lets break this buzz word “Software Programming”,” software”= computer instruction or data , “program” = a series of the steps to be carried out.
Software programming is a sequence of the predefined instructions to the computer (in short) . For every input there are some predefined actions to be performed, for example when we insert our ATM card into the cash dispenser machine the software in that machine has been designed to read the card, on clicking “withdrawal” to dispense cash.

This is something similar to the good old banking culture,where we use to fill up the pay in slip and hand it over to the teller (whose cold looks can even freeze the time) who will send it over for further processing and after spending hours over there u get your long awaited money.

After thinking lot over it I realized that software programming is not an end product(as it is projected to the newbies) its a mean to achieve it. In the above stated example of the ATM cash dispenser machine,software installed wont generate the money or it wont create the ink to print the receipt .But rather logically woven string of actions: when the card is inserted read it when clicked enter open the vault when user wants to wind up print the receipt .

I laugh now at myself for the moments when I used to say “I can do anything” The fact is that I can weave the software into a series of sequential actions to achieve a certain task .Java can be use to make a program to prepare the coffee but it cannot create coffee beans,

Program a Great weekend Guys........