Scraps of Wood and Code
Resisting the packrat mentality.
One of my passions outside software development is woodworking. Perhaps it's my confirmation bias, but it seems like woodworking is a common hobby for programmers.
Assuming such a correlation exists, I've often wondered if there is some causal link. Certainly there are commonalities between the two. Both activities require creativity and structure. The familiar programming concept of "Don't Repeat Yourself" applies equally to woodworking; it's better to create a jig or fixture (a function) than to make a bunch of freehand cuts (copy and pasted code). Both pursuits involve constructing a whole from a series of smaller parts.
Yes, programmers and woodworkers share much in common.
The packrat mentality
When I reach the end of a woodworking project, I'm always left with a pile of scraps: off-cuts, unused lumber, one-off jigs and fixtures. And I do what any good woodworker does with such a pile of would-be kindling...I pack it away in a corner of my workshop with all the scraps from previous projects because I never know when I'll need it later.
As a programmer, I have the same inclination. When I refactor a section of code, I'll often comment it out but leave it in place. What if the new code doesn't work? What if I could use that old code in some other project in the future? I mean, I can't just delete it. Then it would be gone forever. And I probably spent a long time writing that code the first time around. If I delete that code now, what was the point of all the time I spent writing it? Does my life even have meaning anymore?
So I leave it in place. Maybe I don't even bother commenting it out. Maybe I simply rename the procedure to Function MyBloodSweatAndTears_Old()
. Perhaps it's a form or a report. Raise your hand if you have a form or report named "*_previous" or "*_old" or maybe "*_temp". Or do you prefix your old and temporary objects with "aaa_*" or "zzz_*" to set them apart from your real objects?
It's OK. Don't be ashamed. We all do it.
Debt, technically
But we really, really should not do it. All those old form and report objects; those renamed Subs and Functions; those large swaths of commented out code--they're not future treasures waiting to be discovered. They're just more technical debt.
Technical debt is nothing more than today's poor design decisions for which we pay tomorrow. Keeping old code around, stashed in the proverbial scrap pile, is one of those poor decisions.
Here's the really crazy part, though. We can keep all that old code around without having it take up space in our workshop. This--like birthdays and weddings and pretty much anytime cake is served--is one of those rare occasions when we can have our cake and eat it, too.
My wood scrap self-storage unit
Imagine if right outside my workshop I had a two-mile-long self-storage unit where I could keep all my project scraps. And not only could I store all my scraps, but each scrap could go in its own place with a little description of where it came from, why it's left over, and maybe some indication how it could be useful in the future. What's more, I wouldn't have to walk to the end of the two-mile storage unit. I would look through a big book that listed all the scraps I ever stored and give the name and location of the item to my wood-scrap valet. (Shirley, you didn't think I was going to be the one walking two miles in this little scenario?) By the time I closed the big book of scraps, my wood-scrap valet would already be back with the requested item; he is quite efficient.
But wait, that's not all. You see, I've got this buddy, Zack, who's also into woodworking. I could imagine myself telling Zack about this amazing scrap self-storage unit I have and Zack being really jealous because he's working on this project like the one I did two years ago and that jig I made would be perfect for what he's doing now and he could make one himself but since I already made it would I mind going to my wood-scrap valet and asking him to get it for me so I can give it to Zack. And then I would be like, "Dude, you can have an exact copy of the whole storage unit! Plus, you'll also get a copy of anything I add there in the future!!!"
Code self-storage?
So what is this amazing code scrap self-storage unit that lets us programmers clean out our digital workshops but still have access to all that stuff we don't really want to get rid of? Why, it's distributed version control of course!
Once we've got our source code and our forms and our reports and our macros and our queries and our local tables and our references and our database properties all under version control, we never have to worry about really losing something ever again. If we're careful about our scrap labeling (read: commit messages) then it will be easy for us to ask our code-scrap valet (read: Git or Mercurial) to retrieve whatever it is we're looking for.
So the next time you feel the urge to comment out even a single line of code, resist that urge. Remember that you have a two-mile long, instantly accessible code-scrap self-storage unit with plenty of room for all your old code. If you ever need it, it will be there. In the meantime, you'll have a clean digital workshop with no old-code tripping hazards. Happy building!
P.S. You do have your Access applications under version control, right?
Image by Motta Sanchez from Pixabay