Debugging

Debugging is the process of working through the program in a systematic way to eliminate any flaws or glitches. A debugger program is usually included within the IDE.

If a section of code gives you different results from what you would expect, try to make that section of code work in isolation. You may have to give it 'dummy' values to make it work.

If there is something that is supposed to happen but does not, find the section of code that is responsible and make sure that it is running when you expect it to.

If something is happening that should not be, find the section of your code that makes that particular thing happen.

When a computer program does not do what you expect, it is likely that the algorithm that you designed is flawed. Go back to your algorithm and separate it into parts and see how this relates to the program that you have created.

Being able to see what is happening inside a program is very useful when debugging.

You can use print statements to see what value is being held in a variable and remove it later, or use specifically designed debugging tools. Python includes a logging module that allows you to print values and analyse errors.

Bill Sellars explains how programmers use a debugger to step through code and fix errors

Stepping

Stepping is a method of debugging which executes the code one line at a time to check for errors. A debugger can also use breakpoints, points in the code where the program can be stopped to see what is happening and check for errors. A breakpoint can be created by the programmer to halt the program after a certain number of lines of code.

While it is not certain where the word 'bug' (to describe an error) came from, there are records showing that Thomas Edison, inventor of the light bulb, and Grace Hopper, a computer programmer, both made use of the term.

When a moth was found inside a computer that Grace was working on in 1947, she recorded that her colleagues were "debugging" the computer.

Move on to Test
next