Coding Horror

programming and human factors

The Joy of Deletion

I generally dislike these kinds of "Me, too!" posts, but I have to make an exception for Ned Batchelder's excellent blog entry on deleting code. I've often run into this phenomenon with other developers, and it bugged the heck out of me, although I couldn't quantify exactly why. Well, now I can:

If you have a chunk of code you don't need any more, there's one big reason to delete it for real rather than leaving it in a disabled state: to reduce noise and uncertainty. Some of the worst enemies a developer has are noise or uncertainty in his code, because they prevent him from working with it effectively in the future.

A chunk of code in a disabled state just causes uncertainty. It puts questions in other developers' minds:

  • Why did the code used to be this way?
  • Why is this new way better?
  • Are we going to switch back to the old way?
  • How will we decide?
If the answer to one of these questions is important for people to know, then write a comment spelling it out. Don't leave your co-workers guessing.

I have been angrily accused of deleting someone's commented code on more than one occasion. I say, give me a reason not to delete it, and I won't. Otherwise, it's fair game. In my experience this kind of "oh, I'll get back to it" code just sits in the codebase forever, junking up the works for every future developer.

Written by Jeff Atwood

Indoor enthusiast. Co-founder of Stack Overflow and Discourse. Disclaimer: I have no idea what I'm talking about. Find me here: https://infosec.exchange/@codinghorror