Robert's Homepage

Dead Code Is a Liability

#software development

I’m fond of recalling a comment made by a Senior Engineer I worked with as a junior staff member during a code review once. In my pull request, I had noted that a given test suite and the associated code weren’t actually used and working and so I was commenting them out. At the time, he told me to delete the lines instead of commenting them out; citing that “dead code” (e.g., unused, unexercised or otherwise unneeded code) served as a greater liability than source of future implementation and re-use. I’ve reflected often on that point, trying wherever possible - especially in dynamically typed codebases like Ruby or Ruby on Rails based monoliths - to remove “dead code” or unused code paths. Dead code presents a metaphorical occupational hazard to a developer, loose wires waiting to be tripped over during an incident or crisis: at best it creates cognitive impairments to understanding how a software system actually works, and at worst prepares the stage for “bitrot” and, eventually, “we don’t touch that code because we don’t understand how it works”.