It’s generally accepted that copy and paste programming is a bad idea, but what is the best way to handle a situation where you have two functions or blocks of code that really do need to be different in just a few ways make generalizing them extremely messy?
What if the code is substantially the same, except for a few minor variations, but those few minor variations aren’t in things that are easy to factor out through either adding a parameter, template methods, or something like that?
More generally, have you ever encountered a situation where you would admit that a little copy-and-paste coding was truly justified.
I’ve heard people say the will copy and paste once (limiting duplication of code to at most two instances), as abstractions don’t pay off unless you use the code in three places or more. () Myself, I try to make it a good habit of refactoring as soon as I see the need.