Grade 8 Computer Science · Planning before writing
Understanding the problem before solving it
Three questions to answer before writing a line.
Excellent code for a question nobody asked
You were asked for a report, sat down and wrote, and the code works without a hitch. Then it turns out they wanted it by month, and you wrote it by week. No test of the code would have caught that. What should have happened before the first line?
The natural urge facing a new task is to start writing. It feels like progress, and often it is waste — not because the code comes out badly but because it solves a problem that is not the problem that was asked.
| The question | What happens without it |
|---|---|
| What is the input | One writes for the wrong form |
| What is the output | One solves a different problem |
| What are the special cases | One changes the structure at the end |
Why an early change is cheaper than a late one
This is the whole argument, and it is simple. At the understanding stage, changing your mind costs a sentence. At the planning stage, a few lines of a diagram. At the writing stage, a few dozen lines of code. And after the system works and is being used, changing that same decision costs days — because the code, the tests, the data already saved, and sometimes what people have grown used to must all be changed. The same decision, four entirely different prices. That is why the first hour is worth the most.
Example 1 — a solution to a different problem
- A report by months was asked for.
- A report by weeks was written.
- The code works excellently.
- And it is useless to whoever asked.
Example 2 — a special case added at the end
- The program was written assuming there is data.
- It turns out that sometimes there is none.
- The handling requires changing the structure.
- And one question in advance would have prevented it.