2. No True Scotsman
The No True Scotsman (NTS) fallacy is a logical fallacy that occurs when a debater defines a group such that every group member possess some quality. For example, it is common to argue that “all members of [my religion] are fundamentally good”, and then to abandon all bad individuals as “not true [my-religion]-people”.
A common form of this argument in software development is as follows:
It ‘should’ be done this way because it is the ‘correct’ way to do it and any exceptions to this are not true instances of the ‘way’.
You might recognise these:
- “Good code-bases always have 80% test coverage (my one doesn’t though because it’s just a prototype)”.
- “All good developers follow TDD (apart from this controller I am writing, as it is requires a lot of mocks due to external dependencies)”.
Example: Good code should always be DRY.
“Do not repeat yourself” seems like a perfectly logical principle to apply across the board. What could be the downside to only writing code once rather than twice?
When you actually give it some thought though, you realise that there are already many exceptions to the “good code should be DRY” rule that you follow everyday — for example, just take a look at pretty much any implementation of a MVC controller method. You will probably immediately see repetitions in calls to validation and view rendering logic across similar controller methods. Even the notion of keeping one method per route when pages are virtually identical is very anti-dry and boiler-platy, but we (rightly) don’t feel the need to refactor and remove this kind of repetition, as we know it would not be useful to do so.
Here, we are likely to invoke our ‘no true Scotsman’ mentality and say that these instances are ‘not true instances of repetition’, because code fragments just ‘happen’ to be the same, and that we need to ‘keep flexibility’ for code changes in the future.
Rather than thinking this way perhaps the need for exceptions is evidence that the original ‘always be DRY’ premise is flawed (or at least misunderstood).