News for hackers. Stuff that matters.
Re:The Wrong Abstraction (2016) by crazygringo on Sunday July 05, 2020 @12:31PM (#23739877)
Another tip is: if you're duplicating, and they're not lines of code that are visually obviously next to each other, then leave a comment next to both instances mentioning the existence of the other.

There's nothing inherently wrong with duplication, except that if you change or fix a bug in one, you need to not forget about the other. Creating a single function solves this... but at the potential cost of creating the wrong abstraction.

When you're at only 1 or 2 extra instances of the code, just maintaining a "pointer" to the other case(s) with a comment serves the same purpose.

(Of course, this requires discipline to always include the comments, and to always follow them when making a change.)

Re:The Wrong Abstraction (2016) by stormdennis on Sunday July 05, 2020 @01:55PM (#23740507)
Would the risk forgetting to update the comments not be a reason for creating a wrapper method that handled calls to both and contained the relevant advice?