4 ms·
I think DRY should be more "Don't repeat assumptions". Or rather, don't assume the same thing in two different places, especially not implicitly. Avoiding cod
by Gehinnn 2y ago
I think DRY should be more "Don't repeat assumptions".
Or rather, don't assume the same thing in two different places, especially not implicitly.
Avoiding code duplication mostly follows from that.
- jstimpfle 2y agoThat's barely possible because code has to coherently work on a shared goal. But I agree in principle -- reduce duplication of assumptions as much as possible. 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.
- Gehinnn 2y agoI think it's quite often possible! Most of code acts as implication. Given this piece of data (of this shape), I can compute that. Or given I'm a valid object (constructor completed successfully), I can do this and that. 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.