What is debugging?

What is debugging?

Sometimes you might make a program and it doesn’t do what was intended when you try to run it. This could be because of an error in the code that you created or a mistake in the design of the program.

These errors in code are known as ‘bugs’ and the process of finding and fixing these errors is known as ‘debugging’.

What are bugs?

Bugs in a program can vary from those that occur from mistyped commands to issues with the logic of a program. If you are using a text-based programming language, you may get an error message when you run your program, while with block-based languages you are more likely to find that your program just doesn’t do what you want it to.

Debugging is an important skill for your learners to develop while learning to program, as all programmers will need to do it. You should make sure you tell your learners that this is a normal part of programming, you can help them develop their debugging skills through practice.

This will help them reach the point where they can eventually fix issues in their programs independently and reduce the times that learners feel frustrated with having a project not function correctly.

How can you debug your programs?

It is useful for your learners to have an approach which they can follow to help them to debug their programs. Here are five steps for effective debugging that they can use to find and eliminate bugs.

1. Review the task. Your learners may want to refer back to their algorithms in the design stage to make sure they are clear on the intentions of the program.
2. Test the program. Your learners need to run the code multiple times to find the bugs and see what is going wrong.
3. Identify the error. To find bugs in their program, your learners might trace through the code line by line to check it, read the code out loud to see if it makes sense, look at the code with a partner, decompose the program into smaller parts, or look at other patterns with similar code.
4. Fix the bug.
5. Test the program again. Your learners should run the program again to see if it gives the desired outcome. They should also reflect on the effectiveness of their debugging skills.

How can repetition make debugging easier?

The example Logo code below was written with the intention that it would draw a regular hexagon. Unfortunately, the code does not perform in the way that was intended.

FD 100
RT 60
FD 100
RT 60
FD 100
RT 60
FD 105
RT 50
FD 100
RT 60
FD 100
RT 60


The result of testing the code is that the lengths of the sides are not equal and the angles are not equal, so the line doesn’t join up.

If you traced through the code, you should notice that in the seventh line of code the turtle is instructed to move 105 steps forwards, as opposed to 100 steps like the other sides. In the eighth line of code, the turtle performs a right turn of 50 degrees (RT 50), unlike the rest of the code where the turtle turns at 60 degrees. To fix the bug, you could change those values, before testing to see if the program then functioned as intended.

How does repetition make debugging simpler?

The code to draw the above shape could have been written using repetition as REPEAT 6 [FD 100 RT 60]. This code would have been subsequently easier to debug and change because there is only one line of code and fewer numbers to check.

Here is some Logo code that was written using repetition with the aim of drawing an octagon.

REPEAT 8 [FD 75 RT 75]

However, this code also doesn’t work.