3 ms·
Weird that there's no mention of writing tests. After all, they help in explaining the intent behind the given piece of code. With well written tests even the
by Tade0 7y ago
Weird that there's no mention of writing tests.
After all, they help in explaining the intent behind the given piece of code.
With well written tests even the most "clever" implementations become at least reasonably understandable.
Anyway, here's what I do to deal with this problem:
1. Write code (and tests).
2. Switch to some other task.
3. Forget about that previous piece.
4. Get back to it and judge if it's still readable.
If something is readable then it's likely to be modifiable as well.
One classic example of things that I learned to never de-duplicate is the routing configuration. In this instance anything that isn't an explicit list of URLs is usually too "clever" to be readable.
- latchkey 7y agoAgreed. Tests often have the benefit of defining better interfaces, so the implementation details often matter less and code duplication often works itself out on its own.