The practical OCaml programmer first seeks to understand what is going on.
They write unit tests to concretize their understanding.
The practical OCaml programmer then seeks to understand how things work.
And then they write a program and run it through its unit tests.
The Practical OCaml programmer writes unit tests methodically and makes sure that they include corner cases.
For each new implementation, they verify that the unit tests provide code coverage.
The practical OCaml programmer uses structural recursion
for data that were constructed inductively.
And so when faced with a structurally recursive computation,
they first specify it inductively.
The practical OCaml programmer heeds the reverse order of accumulation in tail-recursive programs.
The practical OCaml programmer is not afraid of anonymous functions.
The practical OCaml programmer shuns gratuitous variations
because uniformity in the form (the “how”) fosters unity both
in the content (the “what”) and in the function (the “why”).
The measure of the practical OCaml programmer’s understanding
is the clarity of their discourse, for
a commented code listing does not a report make, and
paraphrasing how a program works does not explain what this program does.
The practical OCaml programmer learned that the road to simplicity is full of bumps.
The practical OCaml programmer doesn’t always start from nothing.
They try to start from what they have already done.
The practical OCaml programmer interacts with the OCaml toplevel loop in a minimal way.
They use the file system for long-term storage.
(This way, they can start from what they have already done.)
The practical OCaml programmer chooses meaningful names and uses auto-completion.
They concur with Albert Camus
that naming something poorly adds to the world’s unhappiness.
(Also, more prosaically, life is too short for misspellings.)
The practical OCaml programmer rejoices at their mistakes as an opportunity to learn,
since to learn from our mistakes, we first need to make mistakes.
When the practical OCaml programmer does not find an error somewhere
(e.g., in their program), they look somewhere else (e.g., in their unit tests).
When reporting an error, the Practical OCaml programmer puts their recipient in position to reproduce this error.
In the spirit of Magritte, they send their code, not a picture of their code.
The practical OCaml programmer is aware that
as pointed out by Edsger Dijkstra,
incomplete testing only
proves the presence of errors, not their absence, since it does not
enumerate all possible cases,
even when it provides test coverage.
They further know that since complete testing enumerates all possible cases,
it does prove the absence of errors.
The practical OCaml programmer lives by Don Knuth‘s tenet
that early optimization is the source of a lot of evil, and by
Kent Dybvig‘s
patient observation that
often, nothing needs to be made efficient if it is done right in the
first place.
The Practical OCaml Programmer authored the following theorem:
if one’s program hasn’t been tested, it doesn’t work.