The Three Numbers

Talin
Machine Words
2 min readApr 16, 2018

--

There’s a programming proverb that goes like this:

The only three numbers a programmer should ever care about are zero, one, and infinity.

Also known as the “zero-one-infinity” rule, it was first proposed by computing pioneer Willem van der Poel.

What the rule means is that you should never build in arbitrary limits on the number of instances of any particular entity. That is, given some computational entity such as directories, hard disks, file handles, and so on, you should only have to worry about three cases:

  • The “zero” case — the entity is not allowed, and will never happen. So for example, the root directory of a file system has zero parent directories.
  • The “one” case — the entity will appear once and only once. A subdirectory will have one and only one parent directory.
  • The “infinity” case — the entity will appear an arbitrary number of times. This does not literally mean infinity, but rather an unpredictable quantity which could range anywhere from zero to an arbitrarily high number.

So for example, under this rule it would be considered bad practice to assume that there will be exactly 2 of some item, or 5. The reason is because chances are somewhere down the road someone is going to want to change that 2 to a 3 or some other number, which is going to require a redesign of your code. Better to anticipate such changes, and design your code up front to handle a variable number of items.

Of course, in practice there are limits on the number of objects one can create — computes have a finite amount of memory, disk space and so on. However, those limits can, and will, change over time. Thus, it is good practice to design programs that can adapt to the limitations of a particular environment, rather than assuming that available resources have a fixed quantity.

Read more in the Engineering Insights series.

--

--

Talin
Machine Words

I’m not a mad scientist. I’m a mad natural philosopher.