If you’re an enthusiastic programmer, you’ve probably written or kept code that you don’t actually need right now. Let’s look at a few scenarios:
- You are creating a new repository for an entity. At this point, your feature only needs to read data from the database, because the data is populated by an external ETL process. However, you also implement create, update, and delete operations “just in case” you might need them in the future. Bad idea.
- You are refactoring some code, and due to business changes, a portion of the code is no longer executed. That was the only place where it was used, but you leave it there anyway, just in case you might need it later. It seems harmless because it’s not being used. Bad idea.
- You are implementing a feature and write a piece of code that seems correct but still needs proper testing and refactoring. An hour later, you change your approach and that code is no longer needed—but you don’t remove it. After all, it’s not being used, and maybe (just maybe) you’ll need it in the future.
At this point, the idea should be clear.
You probably don’t work alone—you’re part of a team. Maybe you have junior teammates, or your team is under time pressure. In these situations, it’s easy to assume that any code in the repository is safe to use.
Even if you work alone, time can become your enemy. In six months or a year, you may not remember the context and end up using code that should have been removed.
Every line of code in your repository should be necessary. Any code that remains can be used by you or your team under the assumption that it is correct.
Unnecessary code also introduces risks. It may rely on vulnerable dependencies, or the code itself may contain vulnerabilities. It increases maintenance effort when upgrading frameworks or dependencies—APIs change, method signatures evolve, and suddenly you’re maintaining code that serves no purpose.
Another issue is test coverage: unused code is rarely tested, which further increases risk.
As a programmer, Team Leader, Engineering Manager, or any technical leader, you are responsible for every line of code in your repository—and every line should justify its existence.