97 Things Every Programmer Should Know

(Chris Devlin) #1

Collective Wisdom from the Experts 189


This is the essence of the claim that tests cannot prove the absence of bugs.
Tests can demonstrate the presence of features, though. But still we have this
issue of size.


The problem domain helps us out. The nature of Go means that the number
of liberties of a stone is not any int, but exactly one of {1,2,3,4}. So we could
alternatively write:


LibertyCount = {1,2,3,4}
boolean atari(LibertyCount libertyCount)
libertyCount == 1

This is much more tractable: the function computed is now a set with at most
eight members. In fact, four checked examples would constitute evidence of
complete certainty that the function is correct. This is one reason why it’s a
good idea to use types closely related to the problem domain to write pro-
grams, rather than native types. Using domain-inspired types can often make
our functions much smaller. One way to find out what those types should be
is to find the examples to check in problem domain terms, before writing the
function.

Free download pdf