3 ms·
This is not to remove all sources of bugs, it is a more succinct way to gain guarantees. Typing, as in making types modelling, your domain so that illegal state
by hurril 5y ago
This is not to remove all sources of bugs, it is a more succinct way to gain guarantees. Typing, as in making types modelling, your domain so that illegal states are impossible to represent implies a lot of tests won't have to be written. Why? Because whole classes of bugs are impossible.
But rest assured, the rest of the bugs are still around so you still need tests. Just not those.
I've worked like this for years now and there's just no turning back.
Do you know how many "null checks" and similar sanity checks are in my code? Close to zero. Do you know why? Do you think I'm a moron or because _those_ things are _actually_ impossible that way.
But rest assured, etc.
It simply cuts down on the amount of certainty that has to be incessantly (re)verified and tested.
Also: when you sit down to model your whole domain in this manner, do you know what you discover? All the things that would be anyway - just further down the line.
"Oh, we don't always have a contract number in these scenarios so _that_ case will have to have a constructor. Oh - that means that this purchase function has to stop "lying" about being able to process any invoice becauase some of them won't have a contract number. Shucks!"
How do you solve that? 4 000 lines of tests and 20 lines of assert hasContractNumber.