Coding by guess and check

Karl Popper described science - I think convincingly - like this:

He described this process as one of alternating cycles of “conjecture” (coming up with a theory) and “refutation” (attempting to falsify or criticise the theory).

I was introduced to this idea by David Deutsch’s book The Beginning of Infinity, where he uses the phrase “conjecture and criticism”, which alliterates nicely. I prefer the more colloquial “guess and check”.

I think this cycle also describes common practises involved in developing software.

I’ve described writing both the original code, and the tests or properties or proofs, as conjectural. In my view these approaches to the same underlying “explanation”, from different angles, buttress each other - acting as potential refutations of each other’s conjecture.

Different modes of expression - source code, examples, properties, proofs - give our minds different affordances to express and explain ourselves. Where these different expressions intersect and either agree or disagree, we get to understand the mistakes we made in each expression.

It’s by challenging ourselves that we can be more confident that our theories, our guesses, about what our code is doing. As Popper translated Xenophanes:

As for certain truth, no one has known it … and even if by chance he were to utter the perfect truth, he would himself not know it; for all is but a woven web of guesses.