3 ms·
Summarized: When writing code, > If you need something once, build it. If you need something twice, pay attention. If you need it a third time, abstract it. I
by B-Con 14y ago
Summarized: When writing code,
> If you need something once, build it. If you need something twice, pay attention. If you need it a third time, abstract it.
I like this rule. Pre-mature re-factoring is a cousin of pre-mature optimization. Having similar code in two places isn't a problem if similar functionality is required in two places. By the time you need it in three places, you don't need similar functionality so much as you need to utilize an abstracted pattern.
Not a hard-and-fast rule, but it's something I personally have tended to gravitate toward myself over time. I used to be more aggressive at refactoring, but now I tend to favor re-using code when re-factoring is not clearly called for.