News for hackers. Stuff that matters.
Re:In Defense of Copy and Paste by crazygringo on Friday February 08, 2013 @05:29PM (#5190503)
Knowing when to refactor is obviously an art, not a science. And with an example as trivial as this, it's not really a very "real-world" example.

A lot of the time, you don't even know if two swaths of code are "coincidentally" identical (don't refactor) or identical in a "deep" way (refactor), even when the program is yours -- you just don't know how the program will evolve.

In the absence of additional information, I usually refactor only when I see three similar code paths, since by that point a project rarely goes back. Over the years, it's turned out to be a surprisingly good rule of thumb.

Re:In Defense of Copy and Paste by bobwaycott on Friday February 08, 2013 @11:23PM (#5191656)
Same here. Doing the same thing three times is always my rule of thumb for when to take a look at refactoring, automating, etc.
Re:In Defense of Copy and Paste by einhverfr on Saturday February 09, 2013 @07:39AM (#5192415)
Also at two, the repetition probably reduces complexity rather than having to deal with both use cases in the same code. At three, assuming the use cases are not any further apart, I think they start to simplify when refactored.