Grade 7 Computer Science · What a program is
Common mistakes about programs
Six mistakes, most of them attributing an intention the machine does not have.
One mistake, six disguises
“The program ran with no error, so it is correct.” “I checked it on an example, so it works.” Both sound reasonable, and both are wrong for the same reason. Spot the reason and you will spot the other four mistakes too.
Almost every beginner’s mistake in this unit is the same mistake in different clothing: assuming the computer understands. Every item on the list is one of its appearances.
- The computer made a mistake — It faithfully executed a wrong instruction. Ask: what exactly does the line say?
- If the program runs without an error, it is correct — Two valid orders can give different results. Ask: what is the expected result, and did I get it?
- If it works on my example, it works — Edge cases are legal and rare — empty, single, identical. Ask: what happens when there is nothing?
- An algorithm and code are the same thing — An algorithm is the idea; code is its translation. Ask: is the idea wrong or the translation?
- A problem has one correct solution — There are many correct ones; one chooses by criterion. Ask: by what am I choosing — clarity, speed or robustness?
- Shorter code is better code — Brevity usually harms clarity without speeding up. Ask: will I understand this in a month?
Example 1 — correcting “it runs without an error so it is right”
- A claim: there is no error message, so all is well.
- Ask: what was the result supposed to be?
- Compare with the result actually obtained.
- An absence of an error is not proof of correctness.
Example 2 — correcting “it works on my example”
- A claim: I checked and the result is right.
- Ask: on which example exactly?
- Run it on an empty list and on a single item.
- Usually one of them breaks the program.