Skip to content
CONTACT

Pike's rules

PROGRAMMING AND BUGS

You can't tell in advance where a program will spend its time: measure first. Fancy algorithms are slow when n is small, and it is the data, more than the code, that dictates the right structure.

— Rob Pike, Notes on Programming in C, 1989
VIDEO.EXE16:9

There are five rules, and they sound like the commandments of a terminal monk: measure, don't guess; don't use complicated algorithms if n is small, and n is usually small; simplicity beats elegance; data rules.

The message is that a programmer's intuition about performance is about as reliable as a horoscope. You think you know where the slowness is, you spend two days optimising the wrong thing, and the real problem was a loop reading the same file a thousand times.

I implemented a self-optimising balanced tree to manage the office phone book. It contains seven numbers. The old scrap of paper stuck to the fridge finds them faster. The scrap of paper also has an elegant magnetic mount.