Grade 9 Computer Science · Abstraction

Common mistakes about abstraction

Six mistakes, most of them abstracting too early or hiding too much.

The code will be replaced, the name will stay

The lines inside a function you will rewrite several times, and no one will notice. Its name and what goes in and comes out you will almost never be able to change. So where is most of the thought worth spending — and why do most beginners do the reverse?

Abstraction is the most powerful tool a programmer has, and precisely for that reason it is also the tool easiest to use wrongly. All the mistakes here are correct use of the tool in the wrong place.

Example 1 — an answer that is too long

  1. Ask what must be known in order to use it.
  2. The answer lists five conditions.
  3. A sign the abstraction is not doing its work.
  4. It saved the user nothing.

Example 2 — a short answer

  1. One must know what goes in and what comes out.
  2. And what happens on failure.
  3. Three things, and no more.
  4. That is an abstraction doing its work.
A scenario: Use someone else’s function? — at each step a course of action is chosen and its consequence shown; 7 possible situations.