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.

Writing is the third stage, and not the first.
The questionWhat happens without it
What is the inputOne writes for the wrong form
What is the outputOne solves a different problem
What are the special casesOne 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

  1. A report by months was asked for.
  2. A report by weeks was written.
  3. The code works excellently.
  4. And it is useless to whoever asked.

Example 2 — a special case added at the end

  1. The program was written assuming there is data.
  2. It turns out that sometimes there is none.
  3. The handling requires changing the structure.
  4. And one question in advance would have prevented it.
At the understanding stage, changing your mind costs a sentence.