Delete All The Codes
Tags: programming, webdev
Published: 2023-08-08 09:15:32

---
title: Delete All The Codes
published: true
description: This article is about is not about writing code, it's about deleting code.
tags: programming,webdev
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xv6zsodbdcpmdkd7bxc5.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2023-08-08 09:03 +0000
canonical_url: https://return.co.de/blog/articles/delete-all-the-codes/
---

This article is about is not about writing code, it's about deleting code. Ok, maybe not all the code. But hear me out.

When I was in fifth grade and starting to program, I was fascinated by big programs. .EXE files that had megabytes in file size whereas my programs only had a few kilobytes. Professional programmers are able to write huge programs and that's a cool thing, I thought.

But, there reality is that code is a liability. As soon as you write it, is your team's legacy. A legacy in reality can be something good like a house but it can also be something bad like debts. In software development, it is quite often the latter, unfortunately.

## Feed Your Code

![Cookie Monster likes cookies](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/60jauxc99mu78m8cnrgi.jpg)

One might think that code once written can just stay there for free. It doesn't do harm, right...right?

Code needs to be maintained. It needs love and care to stay healthy otherwise it might break and take your beloved app with it.

There are all kinds of things need to be considered:

- Upgrading to a new version of a library or framework that requires code changes
- Updating to a new version of the language you use
- Fixing security vulnerabilities in your code base
- Keeping builds green (timing changes might break things)
- Changing requirements might require changes in code that you thought you'd never have to touch again
- Changing infrastructure (e.g. new data base) might require changes (especially if the code is not decoupled)

## The Best Code Is No Code

Where my younger me had a deep admiration for big program, my older me has learned that code that does not exist is actually the best code. It doesn't need any of the things discussed in the previous section.

I don't have any personal relationship to my code anymore (which is actually not my code by our team's code anyways) and so you shouldn't.

![Anakin killed them all](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0q4nup96ahmu5o158w0m.jpeg)

I actually feel happy and relieved deleting code.


## Tidy Up

![KonMari keeps it tidy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0wn4l7fa8tzh6xvodsqf.jpeg)

To delete code, I actually follow a couple of practices:

### Boy-Scout-Rule

The Boy-Scout-Rule is a general practice of continuous improvement. It basically says: Leave the fire place cleaner than you found it. Or in more technical terms: If you are working on a part of code, try to improve things in the area that you are working on even if it is not strictly necessary for your current task.

That includes cleaning and deleting code. Most often, your editor or IDE will tell you about unused code. Delete it. No excuses. There should be tests covering it, if the code is actually necessary.

### Refactoring

Sometimes you start with a new bigger feature and implement it in the most basic way (TDD, wink wink). But as soon as you add new features around that code, it might need some refactoring.

If you did it right, most of the time you should be able to actually delete a significant amount of code. For me, this is like the reward I get when I we did a good refactoring. It let's me delete code. I love it.

### Zombie Code

![Brains](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tocsgu16u91nfuikgp2l.jpeg)

This is a tricky one. You might have code that is used (by tests) but actually not in production anymore. So it looks like it is used but it is actually some undead code disturbing your neighborhood. This is the case e.g. when you have APIs that are covered by unit tests or even integration test but which are not used, neither by a UI nor by customer.

This needs a check from time to time. Could be done as a regular item in a team meeting or task in a maintenance sprint etc. Obviously, you could also explicitly deprecate APIs which are used by customers and mark them for removal.

## Time Travel

You might say "But I might need that code!". You might also know the answer. Use your version control system of choice to get the code back. Yes, it might not immediately work but the effort to keep code alive is most often higher. Also, in 99% of the cases, no don't need that code ever.

## Conclusion

Keep you code clean and tidy. Delete as much code as you can. Thank me later :)


*Cover image by <a href="https://unsplash.com/@ujesh?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Ujesh Krishnan</a> on <a href="https://unsplash.com/photos/7ySd00IGyx4?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>*