Dead Code Is Dead Code

As a programmer you’re going to come across code that are residue of dead features. You need to figure out what you are going to do with the mess. Are you going to delete it or leave it?

You have several options.

 Door #1. Exterminate dead code. The idea is that you’re not going to use it anytime in the near future and it’s taking up space. So you delete it.

  • Key Benefits
    • Less lines of code, less problems
    • Easier to navigate through your code base. No need to scan through code thinking if it’s in use or not 
    • No dead code laying around
    • IF you wrote tests for these, you’re test suite will be reduced
Door #2. Walking Dead. Let it be in the codebase because it’s not doing anyone harm. The possibility of brining the code back for a different feature
  • Key Benefits
    • This is only true if you know the time line you’re going to reuse the code
    • Saves time implementing the feature as you have a pieces of the feature or all of the feature ready with this old code 
Door #3. Give up. This world is too harsh for you to bear. 
  • Dead

I’m going to make couple assumptions. You use tools like Git, or Mercury. Less lines of code (LOC) makes codebase easier to read. Less time it takes to run the test suite the better. With these assumptions the benefits of door #1 far outweighs those of door 2.

The only benefit door 2 has is if you’re team decided to reuse the code soon.

However, this is also possible in door 1. When you use a subversion tool you’re writing commit messages with your changes to quickly notify others what you did.

git commit -m ‘Removing daily mush feature as it is not being used anywhere in the project. This feature allowed us to deliver coupon to users emails’

Now that you have a good commit message to reference to. In the future if you need to see what that commit did (what methods you deleted), you’ll grep through the logs and find your old commit.

git log --all --grep='daily mush'

Now you’re free of dead code and you’re able to revert back to the original state if it comes down to it.

Leave a comment and let me know what you think!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s