Computer science
Debugging
Bugs are part of the game: learn to hunt them systematically instead of guessing.
What you need first
Your bike light will not turn on. You try the switch, check the battery, wiggle the cable: you search for the fault step by step. That is exactly how people who program work every day. Errors in a program are called bugs, and finding them is a real skill you can learn.
Bugs are normal
First things first: a bug is not a failure. Even professionals constantly write code with errors, every single day. The only difference is how they deal with it: they are annoyed for a moment, and then they go hunting. Every bug you find makes you better, because along the way you understand what your program really does.
Goal
Count from 1 to 10
Click the line with the bug.
Search systematically instead of guessing
Changing things at random only finds bugs by luck. Two questions work better: what should happen? And what actually happens? Write down both answers. The bug hides exactly in the gap between them. If your program is supposed to double its input but turns the input 3 into 9 instead of 6, you already know a lot: the line that does the calculation is the suspect, and that is where you look first.
Line by line and small tests
The strongest technique is to play the program yourself: walk through it line by line and after each line write down the current value of every variable. At the latest where your notes differ from the expected value, you have found the bug. Small tests help with this: feed your program an input whose result you know for sure, and compare.
Exercises
0 of 6 solvedTime to try it yourself. You can't break anything, every attempt counts.
Your program does not do what you want. What is the best first step?
A program is supposed to double the input. A test shows: input 3, output 9. Where is the bug most likely?
A program is supposed to calculate 5 plus 3, but the bug makes it calculate 5 times 3. What number does it output?
The bug hides exactly in the … between what should happen and what actually happens.
A program is supposed to add the numbers 1 to 5, but because of a bug it skips the 5. What sum does it output?
Match each debugging technique to its purpose.
Where this leads