TDD Is About Writing Counter-Factual Statements

Writing unit tests first, in the manner of test-driven development, is some kind of “wishful programming”: you create a counter-factual situation in the test code, e.g. one that uses types and methods that don’t even exist.

Then you add the implementation to make the counter-factual statements (and failing tests) the actual reality.

You turn a lie into the truth, a thought-experiment into reality.

See also:

I’m not sure what to do with this association, yet. It just came to mind when used the term “wishful programming”, or “wishful thinking”, in a conversation recently.

In the tradition of linguistics and analytical philosophy, “counterfactuals” are a whole subject to study. Since I’ve now made the mental connection from TDD to “counterfactuals”, maybe I can back-port some interesting tid-bits from linguistics to TDD. It’s not very likely – then again, folks figured out how to replicate the good parts of a fringe book on architecture to Design Patterns for programming.

I picked up this term from Gio Lodi’s book, Test-Driven Development in Swift, by the way.

Receive new .