Re:DRY Is a Trade-Off
by Ma8ee on Friday December 18, 2020 @01:06PM
(#25469960)
I see similar arguments come up over and over at HN, and I say they stem from a fundamental misunderstanding of DRY. What we must not repeat is not lines of code, but how we do certain things in the code. That is, it’s fine to repeat syntactically identical sections of code if their semantic meaning is different. But if the semantic meaning is the same, they must never be repeated because we must never have several definitions of the same thing in the same program. This is similar to the concept of normalisations in DBs.
[ Parent
| on HN ]
Re:DRY Is a Trade-Off
by takeiteasyy on Friday December 18, 2020 @01:11PM
(#25470024)
Could you give an example of syntactically identical sections of code with different semantic meanings?
y = m * x + b
can refer to the distance a car has traveled over time at a fixed speed with a starting point as well as the cost of ordering a certain quantity of an item with a fixed shipping cost
that's my best attempt at an example
That is better than I managed to come up with on short notice.
Thanks. It was inspired by an Uncle Bob example.