3 ms·
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
by crazygringo 14y ago
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.
- bobwaycott 14y agoSame here. Doing the same thing three times is always my rule of thumb for when to take a look at refactoring, automating, etc.
- einhverfr 14y agoAlso 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.