Before going to explain debugging, I want to discuss, what a program means. As every computer student knows, a program is a sequence of instructions that specifies how to perform a computation. Computation can be mathematical or symbolic. Symbolic computation means computations like searching and replacing text in a document. Usually a program may have instructions to get input, display input, mathematical operations, conditional operations and iterative operations.
There can be chances to occur errors in the programs. Those errors are called as bugs. Tracking and solving those bugs is called as debugging. Debugging is one of the most intellectually rich, challenging, and interesting parts of programming. There is a classification regarding the type of errors.
- Syntax errors
- Runtime errors
- Semantic errors
Eg : (1+4) is correct but 1+4) is a syntax error.
Runtime errors cannot be seen until program execution starts. It usually indicates that something exceptional has happened. So it is also called as exceptions.
If a Semantic error occurs, the computer will not generate any error messages. But the program will do something different than it is supposed to do. This error occurs due to the logical mistake of the programmer.
Debugging is also like an experimental science. Once you have an idea about what is going wrong, you modify your program and try again. If your hypothesis was correct, then you can predict the result of the modification, and you take a step closer to a working program. If your hypothesis was wrong, you have to come up with a new one. Programming is the process of gradually debugging a program until it does what you want.