Grade 7 Computer Science · Bugs and testing

Three kinds of bug

Syntax, running and logic — and why only the third is truly dangerous.

The bug the computer will not help you find

Code that is not legal at all is caught before the program even runs. Dividing by zero stops it midway and says where. But there is a third kind that slips past both barriers without leaving a trace — and it is the only one that needs a method.

Until here we met bugs one by one in each unit. Now it is worth ordering them, because what matters is not what each bug does but when it shows itself. The three groups differ in exactly that, and telling them apart changes entirely how one searches.

The later a bug shows itself, the more it costs.
The kindWhen it shows itselfIs there a message
SyntaxBefore the runYes
RunningDuring the runYes
LogicOnly if you testedNo
total = 0
for n in [1, 2, 3]:
    total = total - n
print(total)

Why the distinction saves time

The first two kinds hardly require searching at all: the message says what happened and where, and most of the time goes on the fixing itself. The third kind is the exact opposite — the fix is usually one line, and all the time goes on finding that line. So it is worth first asking which group the bug belongs to: if there is a message, read it and move on. If there is no message, no one will help you and you need a method. The rest of the unit is about that method.

Example 1 — recognising a logic bug

  1. The program ran to the end with no error.
  2. Output appeared and looked plausible.
  3. But it is not what was expected.
  4. That is the only kind that needs a search method.

Example 2 — why syntax is the cheapest

  1. The bug is caught before the program even runs.
  2. The message points at the right place.
  3. There is no need to search at all.
  4. All the time goes on the fixing itself.
Sorting: Which kind of bug is it? — 6 items into 3 groups (Syntax, Running, Logic), with a check and a reason for each item.