Debugging – An Important Aspect in Programming
In this tutorial you will learn about Debugging – A Important Aspect in Programming, Detection or Finding of the Bug, What the bug or fault is, Where it has occurred, How it is caused, Important Factors to Consider while debugging, Debuggers utilities and functions – Step-By-Step, Breakpoint.
After developing a program the next step is to test the program to find whether the program function and produces output as desired. In real situations the program when run immediately after developed will give errors of different types say syntax errors or logical errors and so on. This is where debugging terminology figures out. Debugging is the step by step process of finding errors or bugs in a program so that the bugs can be removed to make the program function in the way it was desired. There are several tools available to do the above defined debugging process. These tools are called debuggers.
As we have seen debugging process involves the identification of bug in a procedural way the sub events involved in this debugging process are namely:
Detection or Finding of the Bug:
This is the primary process or activity of a debugging process. For doing this with key attention the output or the value at each stage of the module or program must be checked. If any discrepancy is found then with greater attention that sub portion must be checked to find the values passed to each variables and the output that occurs from each process in that subdivision. One can also add some temporary statements or print or output statements for checking the values of variables. These temporary statements must be removed carefully after the debugging process. In some cases it may be necessary to recreate the bug to identify where it has occurred. Thus the main idea of this step of debugging process is to identify
What the bug or fault is – This can be done by recreation of bugs or by careful checking of values
Where it has occurred – By writing temporary print or output statements or finding the place where value is changed or reasons why data is not in proper format and so on.
How it is caused and so on.
Having done the major process of debugging the next step in debugging is to fix the error or bug.
Bug Fixing or Error Correction: This is also involved in the process of debugging because while we fix an error or bug there is possibility that it may give raise to some other bugs. If it happens again the process mentioned above namely detection, correction takes place. This continues until the system is found to be bug free.
Important Factors to Consider while debugging
- While correcting or fixing a bug always make it a habit to make comments containing description about date, purpose of fixing, username who fixed the bug and so on. This is very essential because this will be helpful if the person who made the bug fixing later on want to refer the bug for some reason for fixing some other fix or it would be helpful for other users since it act as a documentation which provides an easy reference.
- Make it a practice that while debugging to make a change and test it immediately. This is because when a change is made to the existing code it may pave way for some more bugs. After ensuring that the corresponding fix works fine by testing then go for next change. In other words it is essential to be systematic in approach while debugging.
- It is very essential to remove the temporary code added just for debugging purposes like temporary print statement to check the value of variables and so on.
- When a fault is found in debugging process after correcting and fixing it always have a broader vision and think whether the same fault or similar situations can occur in other parts of the program. This vision will help in reducing the time in debugging process.
- While debugging it is always good to follow the modular approach. Since by viewing details in module level greater details and bugs can be detected if any existing and also correction of bugs becomes easier at the modular level and proceed as such to different modules and then proceed to interfaces between modules.
- Before starting the process of debugging it is good to have an overview of what the program or modules is about and prepare a step by step approach. This process though takes time will help in proceeding systematically in debugging process and helps while the debugging is going on.
- First a step-by-step eye viewing manually on the program or module is needed to find what happens to value of variables and to decide whether any temporary statement needs to be inserted. After this if the process is complex debugging tools or symbolic debuggers etc can be used for debugging process.
Having known a lot about the concept of debugging now let us see how to do this process of debugging in a simplier and efficient way. This is done by the use of debuggers
Debuggers have many utilities and functions in it to name a few are
Step-By-Step – It helps watching the variables or value of the program in each step and therefore thorough analysis can be made easily.
Breakpoint – This is used for pause the program at any time needed. Say for instance if a user wants to check the value written in a file when enter key is pressed then after enter key is pressed if this breakpoint is used then program is paused and the user could check the file.
The above mentioned is only a few of the numerous abilities or functions available while debugging using debugging tools. Whatever may the tool used it is important that one should definitely debug their program or in other words it is vital to follow the debugging step in software development life cycle in order have a quality product.