3 ms·
As soon as I use the same code twice, I try to make it into a generic component. The same logic twice becomes a function. The same concept twice becomes a packa
by majewsky 7y ago
As soon as I use the same code twice, I try to make it into a generic component. The same logic twice becomes a function. The same concept twice becomes a package in a shared library.
Emphasis on "try": Some languages make it difficult to avoid code duplication in certain situations. (Looking at you, Go...) I allow code duplication if it's more readable than trying as hard as possible to refactor out common parts.
For Go-based API-driven services, we have collected some of these reusable modules and functions at https://github.com/sapcc/go-bits https://github.com/sapcc/go-bits.
- thunderbong 7y agoRule of three https://en.m.wikipedia.org/wiki/Rule_of_three_(computer_programming) https://en.m.wikipedia.org/wiki/Rule_of_three_(computer_prog...
- wry_discontent 7y agoThe thing I've never understood about this is how to track 3 times. I can remember something twice, but the third time, I'm drastically less likely to realize it. Also, this seriously breaks down when multiple developers are working in the same area.