Friday, March 1, 2013

Debugging !

Lets not talk about debugging first and talk about 2 other things:

 1: 
Have you imagined what might be happening when an engineer decides to create a new plane with a new design ? (We assume that one can do so ;) ) He thinks about the purpose, safety, design etc. He might think about  aerodynamics, propulsion, fuselage, mass, structure etc. The design process would also include the use of Computational Fluid Dynamics (CFD). In short the process before building some physical component takes a long time. Even after they have built some physical model, they need to test it in wind tunnel to be sure about it. Similar amount of effort is given the construction/engineering of other components.
If you want to test your physical component in real, then you might have to rent/buy a wind tunnel at relatively higher price then of an average computer. Also if some other electronic/mechanical component fails at run-time, finding the actual problem and fixing it is a difficult task.

 2: 
Imagine you have a Mercedes-Benz W116. The car was excellent product when it was built and you are not maintaining it properly. It continues to cause problem frequently because you are not maintaining it properly. You have also learned to fix the problems with car as and when they arise.It might take some time some day, but you some how fix it.
On one fine day your mom asks you to drop her to a church and in-between on the road the car causes problem. But, as you have become familiar with problem solving you would be able to solve it and car start again and you would be able to successfully drop your mom to church. In this situation your mom should not be happy thinking that "owww, my son could correct that!"; instead she should think like "oh! how could this happen ? car stopped ?!! ".

Now that we have laid out enough foundations that needs clear out the point that i want to show; we can discuss the main topic of this post. That is "Debugging".

We, the software craftsman/developers write software/applications that people use in day to day life. But we are not able to develop them on the first run. Sometimes things would go wrong with the software that we are developing. And when things go wrong; the bug comes out, we must find the cause and fix it.

To fix the problem we must look "into" the software while it is running. Now compare it with the aircraft system. Imagine what hey might be doing when an issue rises with the engine of aircraft ?

Surely the software craftsmen/developers have more power when compared with aeronautics people. They can not see what is happening in the engine while it is running at 10,000 RPMs while the software developers can pause the execution of software on their machines without any significant amount of investment. Developers do not have to got to wind tunnels in order to see something in action.

A software developer/craftsman can put a break-point and then do the magical things like step in, step out, runt to cursor etc. Recently I have met some some people for whom the debugger does not exists. They do not know about the remote debugger available. They do not know how to configure xDebug with PHP. They do not know that GDB exists. Some people think that they are using exotic languages like Ruby and Python and debugger is not there for their language. But; by thinking wrong directions they are missing something really important.

Sometimes people forget that debuggers exists and we can see what is happening in your code in real time line by line, variable by variable. We can see all the variables, objects etc by putting a watch on them !! If we are doing web development then we can see all the parameters in the variables in the real-time inside our IDE(although non visual-command based debuggers exists,  but i prefer  debugging visually)(eg we can see $_GET, $_POST etc in php while debugging in Netbeans).

We can see what is happening in our software step by step, line by line; Now imagine what people in aeronautics and other industries would had done if they had such power at their fingertips at such low cost ? We are underestimating the power that we have with debugger and in-turn underestimating ourselves.

But make sure that it does not become a daily and routine activity. Debugging is not central activity of development process. It should not be daily activity as it was with our virtual/imaginary car.

Your boss should also think same as your mom. Debugging should not become routine as it was with car. Neither some one should be proud of it!

Also the boss should not be proud of a person with good debugging skills!

We should work in such way that odd situations like these do not rise!

Write such code that no problems get raised and in-turn you do not have to debug. But when the problem gets raised be equipped with debugger of your language and solve the bug well. Do not forget to take advantage of good debugging tool, but make sure that you are not making it continuous activity.