Have you ever looked at a piece of code and thought:
I think this works, but I can‘t quite convince myself it‘s correct?
The logic is relatively straightforward.
But the state is distributed across a handful of variables that could be combined in ways that don‘t make sense.
And as soon as you start working on it, you find yourself mentally tracing through every code path to make sure none of the illegal variable combinations can happen.
Whenever this happens, one thing is part of the problem: The model of the domain was only ever implicitly there, in the head of the programmer, and not written down in code.
In this series, I want to show you how to formulate those models in code, in TypeScript, so that the code gets easier to understand for everyone not currently writing the code (colleagues, but also future you!). We‘re going to take a small but realistic application and refactor it from a hidden-model style to an explicit-model style.
Read on...