Java Child / The Machine Does Exactly What You Said

Tracing A Program By Hand, Slowly, On Paper

Running instructions in your own head, one step at a time, is the fastest way to build real understanding.

Take a set of instructions and a sheet of paper. Rule columns for each value the instructions care about. Now walk through the steps as though you were the machine, updating each column as it changes, refusing to skip ahead and refusing to assume. It is tedious. It is also the exercise that separates people who feel programming is guesswork from people who feel it is mechanical. Somewhere in your third or fourth trace, the abstraction stops being an abstraction and becomes something you can watch moving.

The temptation is always to skip it, because you are sure you know what happens. That certainty is precisely the thing worth testing. When a hand trace and the actual behaviour disagree, you have found something valuable: not a bug in the instructions necessarily, but a bug in your mental model, which is the more expensive of the two. A wrong model will keep producing wrong instructions long after this particular problem is fixed.

Trace with small inputs, because the point is not to compute a result but to observe a mechanism. Two or three items is plenty. Choose examples that include the awkward cases, such as nothing at all, or two identical things, since those are where the interesting disagreements live. Keep the paper. Comparing a trace you wrote yesterday with behaviour you are seeing today turns a vague sense that something is off into a specific step where expectation and reality parted company.