Something I should know

jdavidb on 2005-11-29T13:14:34

If you are going to execute a particular piece of code twice, then you are going to execute it three times some day, and you should therefore put it in a subroutine. (Or module.)

It's always true, or at least true so often that you should always assume it is true so you don't hate yourself later.

The fun part here is I'm thinking about this after doing the right thing for a change, rather than the wrong thing: I cut and pasted some code and then when the idea to refactor suggested itself I considered not doing it. But I did, anyway, and immediately after finishing remembered, "Oh, yeah: I'm basically enhancing an existing program that handles case 1 to handle case 3 as well. Some day, somebody is going to ask me to handle case 2."

And all this by only four minutes after the sun comes up today.