MyLeoNes™

Debugging: finding and fixing mistakes in code — Technology, 11–13 years

Programs often fail because a small instruction is wrong, missing or misunderstood. Debugging is the careful process of observing what happened, forming a possible cause, testing it and changing the program until the result is reliable.

Treating failure as evidence

Debugging is not random fiddling with code. You compare the result you wanted with the result you got, then use the difference as evidence about where the program went wrong. A useful fix changes one likely cause and checks the result again, so you learn which change mattered.

Why programmers debug

People write instructions, but computers follow them exactly, including an unintended detail. As programs became larger, simply reading every line could no longer guarantee that they worked. Debugging developed as a way to investigate real behaviour rather than trusting what the programmer meant to write.

Fixing a points counter

A game should add 10 points after each star, but after two stars it shows 10. First, test one star: the score becomes 10, so the addition works once. Then test two stars and inspect the update: the code resets score to 10 instead of adding 10 to the old score. Replacing that reset with score plus 10 gives 20.

Changing too much at once

When a program fails, changing many lines at once feels efficient: perhaps one of the changes will fix it. But then a successful result does not tell you which change mattered, and a new error may hide the original one. Small, recorded changes make the cause easier to identify.

Beyond code

Debugging is used in apps, games, websites, robots and even spreadsheets. A team may reproduce a problem, record what was expected, add a test, and check the fix on different devices. The same habit is useful for a broken model or a tangled craft project: observe first, change one likely cause, then test.

Keep exploring

Other languages

Loading MyLeoNes™…