Why DRY?
I think this is a very important concept to understand as a programmer:
It seems to me that some programmers see themselves as Terminators: out to eliminate all code duplication with extreme prejudice; sometimes, perhaps, without even considering the trade-offs involved. Every time you remove duplicated code, you add a level of indirection, and as you’ve probably heard before, all problems in computer science can be solved by another level of indirection, except for the problem of too many levels of indirection.
And, I didn’t know about the term “Rule of three”, but it’s a guideline I have been trying to stick to:
- Write a piece of code.
- Write the same piece of code again. Resist the urge to generalise.
- Write the same piece of code again. Now you are allowed to consider generalising it.