Or rather, don't assume the same thing in two different places, especially not implicitly.
Avoiding code duplication mostly follows from that.
Or rather, don't assume the same thing in two different places, especially not implicitly.
Avoiding code duplication mostly follows from that.
One way that helps with that is creating abstractions. I don't mean clever grandiose abstractions, those are extremely hard to get right. I mean precisely those abstractions that factor shared code.
But even before that, it's important to get the control flow right to minimize doing the same thing multiple times in the codebase. Because even when the implementation is in a central place, calling it multiple times from different locations is what you say, duplicating assumptions.
However, very often, unstated assumptions sneak in.
For example, assuming to understand how to interpret a certain string, which usually causes all kind of escaping issues.