|
|
|
|
|
by glyphobet
4983 days ago
|
|
This is a bit too simplistic. The rule of three really should apply to similar patterns that emerge naturally in the course of implementation. His example code consists of two four-line functions that share a common if-else control structure but call totally different functions. That's not copied-and-pasted code, and it's not enough similarity to warrant generalization even after three or four replications. (And it would be better modularized away completely using inheritance or delegation, instead of a state machine.) When it comes to copying and pasting identical blocks of code that actually do something, even having two copies opens you up to copy-and-paste bugs. Waiting until you have a third copy is too late. Don't ever copy and paste. |
|