News for hackers. Stuff that matters.
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.
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?
Re:DRY Is a Trade-Off by hknapp on Friday December 18, 2020 @02:05PM (#25470637)
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

Re:DRY Is a Trade-Off by Ma8ee on Friday December 18, 2020 @02:17PM (#25470782)
That is better than I managed to come up with on short notice.
Re:DRY Is a Trade-Off by hknapp on Friday December 18, 2020 @03:17PM (#25471388)
Thanks. It was inspired by an Uncle Bob example.
Re:DRY Is a Trade-Off by Ma8ee on Friday December 18, 2020 @02:10PM (#25470704)
Only contrived ones without supplying quite a bit of context.