Better Than Writing Code?

Image credits: Photo by Christina Morillo from Pexels

Software developers love to write code. We enjoy talking about different programming language. We like arguing about architecture concepts, frameworks and libraries. We discuss paradigms like object-oriented programming and test-driven development. For many engineers, it is the joy of writing code that got them interested in the software industry. However, there is one thing that is almost as good but often neglected.

Removing code! Yes, you heard me right. Removing code is almost as powerful as writing code, sometimes even more. That is because code is not for free, even if you exclude the initial cost of writing:

  • Maintenance cost: Code needs to be read, understood and adapted for as long as software products are used.
  • Potential for bugs: More code means more potential for bugs that can cause issues. Without code, there are no bugs.
  • Performance overhead: In some cases, additional code can make an application slower to respond and more expensive to run in terms of resource usage.

You see, adding more code is only a good idea if it is worth the additional cost. Cleaning up your code base is the equivalent of getting back into shape after gaining weight from too much food and too little exercise. During cleanup, the inner structure of your software becomes more healthy again, and it can show on the outside, too.

Here are some examples on when to consider code removal:

  • Features that have never been used or delivered (e.g. incomplete features that are no longer a priority).
  • Leftovers from former migrations like old feature flag toggles or deprecated APIs.
  • Clearly unused code sections (e.g. leftovers from refactorings, prototyping etc.).
  • Excessive abstractions that never paid off and can be replaced with simpler approaches.
  • Outdated comments and documentation that are no longer reflecting the current state.
  • Tests that are no longer verifying desired behavior (maybe requirements have changed over time).
  • Self-built features that can easily be replaced with a 3rd party software, framework, library or cloud solution.
  • Overly complicated implementations that can be replaced with much simpler solutions.

It is remarkable how many projects carry unneeded code around for years on end. Often, it is a good idea to remove such dead weight. Of course, there are exceptions, and developers need to ensure that removed parts are actually safe to delete. When in doubt, it helps to coordinate with other people from the development team.

The takeaway here is to reflect on obsolete code in our software repositories, since maintenance costs are real. Keeping code for some eventuality in the future is not an excuse. Version control systems like git can easily bring back old code if needed.

Now, what is your experience with code cleanup techniques? How can we prevent accumulating dead weight in software projects in the first place?

#SoftwareEngineering #CodeCleanup #Simplicity #Maintenance #Bugs

Bastian Isensee
Bastian Isensee
Software Engineer (Freelancer)

Quality-driven Software Engineer focused on business needs, knowledge sharing, FinTechs, Golang and Java