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.

Jeff Atwood

Written by Jeff Atwood

Indoor enthusiast. Co-founder of Stack Overflow and Discourse. Disclaimer: I have no idea what I'm talking about. Let's be kind to each other. Find me https://infosec.exchange/@codinghorror

⏲️ Busy signing you up.

❗ Something's gone wrong. Please try again.

✅ Success! Check your inbox (and your spam folder, just in case).

Recent Posts

map of the United States via rgmii.org showing all 3,143 counties by rural (gold) / metro (grey) and population

Launching The Rural Guaranteed Minimum Income Initiative

It's been a year since I invited Americans to join us in a pledge to Share the American Dream: 1. Support organizations you feel are effectively helping those most in need across America right now. 2. Within the next five years, also contribute public dedications of time or

By Jeff Atwood ·
Comments
Let's Talk About The American Dream

Let's Talk About The American Dream

A few months ago I wrote about what it means to stay gold — to hold on to the best parts of ourselves, our communities, and the American Dream itself. But staying gold isn’t passive. It takes work. It takes action. It takes hard conversations that ask us to confront

By Jeff Atwood ·
Comments
Stay Gold, America

Stay Gold, America

We are at an unprecedented point in American history, and I'm concerned we may lose sight of the American Dream.

By Jeff Atwood ·
Comments
I’m feeling unlucky... 🎲   See All Posts