Chapter 12. Two is Too Many
There is a key rule that I personally operate by when I'm doing incremental development and design, which I call "two is too many."
This rule is how I implement the "be only as generic as you need to be" rule from Code Simplicity.
Essentially, I know how generic my code needs to be, by noticing that I'm tempted to cut and paste some code, and then instead of cutting and pasting it, designing a generic solution that meets just those two specific needs.
I do this as soon as I'm tempted to have two implementations of something. For example, let's say I was designing an audio decoder, and at first I only supported WAV files. Then I wanted to add an MP3 parser to the code. There would definitely be common parts to the WAV and MP3 parsing code, and instead of copying and pasting any of it, I would immediately make a superclass or utility library that did only what I needed for those two implementations.
The key aspect of...