Write deletable code

It may seem antithetical to software development, but I believe deleting code is often much more important than people think. The ease at which it can be done is often overlooked by engineering teams, so removing code is usually flat out tough.

Writing code is, however, usually pretty easy. Good code, bad code, adding it is the part that excites developers the most. It’s what we’re best at. Our job is to write code and contribute to whatever we may be working on. So doing the opposite and removing from the codebase simply feels backwards.

We can group our reluctance to remove code into two categories: 1) the wrong feeling you get from doing it, and 2) the technical unknowns and worries you have to overcome.

Selecting a block and hitting the backspace key feels wrong. It feels unproductive, it makes us feel like failures. We spent time writing this code, only to now be deleting it.

But what if we accidentally delete something unrelated in the process? Maybe we’re removing a defunct feature, and the code we deleted is actually shared amongst two features. Or, what if we want to reuse this code sometime down the road? Now it’s gone, gone forever.

We should fight these roadblocks. Removing code should feel right, productive, fine. It should also be easy, unexciting, and straightforward.


 What can we do to make this possible?

Or, what does deletable code look like?

  1. Our code must be properly isolated such that when deleting code, it’s obvious what we must delete.
  2. Related to #1, our code must be well tested. When deleting code we should be able to have faith that deleting one line won’t unexpectedly break something unrelated. Tests help us prove that.
  3. When adding or removing code, we should split our changes up into logical commits. Reverting additions should be easy, as should reverting incorrect deletions.
  4. As a prerequisite to #3, we should use Git or another version control system, so that deleted code can live in our history, and so that reverting deletions is possible.
  5. We should write clear code that is easy to reason about, so when we eventually delete it’s obvious what to delete.

This is in no way an exhaustive list of ideas, but it’s hopefully enough for you to consider and expand on.

The importance of removing code isn’t a new idea. I’ve actually visited offices with leaderboards on the walls displaying which team members have removed the most code. Additionally, many people smarter than I have written some great pieces on the topic.

I encourage you to consider the value in removing code, and keep the end in mind when contributing new code. Write deletable code. It’s usually hard, but it doesn’t have to be.


Now read this

What are internships for?

Many people are confused by internships. They think interns are just underpaid employees, who’s only job is to grab coffee. That’s typically not the case. Internships are a great way to gain real world knowledge related to your... Continue →

Subscribe to Colby Aley

Don’t worry; we hate spam with a passion.
You can unsubscribe with one click.