the thing about deleting code

Refactorings, clean ups, consolidations – doesn’t matter what you call it, but there’s something calming about finding ways to touch code without the intent to functionally change or improve it. It’s like cleaning the workshop. And much like cleaning the workshop, there’s an art to focussing disproportionately on actually: deleting code.

Deleting code is the real-world equivalent of taking stuff to the trash bin. People who do not regularly take stuff to the trash bin are either dead or widely considered as hoarders. Both is concerning.

Actually going there and throwing stuff out is both incredibly satisfying and not exactly easy to get started with. But not doing it is even harder in the long run, so the best time to pick up the habit is probably now. What is a good place to start? Let me explain my thought and action process.

I consider myself occasionally to be a rather simple person: I’d take every opportunity to get rid of something that I personally just don’t like. Code is very easy to either like or not like: very obfuscated, poorly documented hot mess of nested if-statements? That’s a promising candidate for something that just needs to go away. There’s often no point in trying to save something that’s beyond salvageable. To keep it brief, there’s a three step process that kick off then:

First, you extract whatever useful you can find within the can of shit. That might be a lot, or not much at all, but start over in a fresh file or module or library and just copy what you need. You’ll probably feel the exciting spark of not having a single useful test helping you in that, and that’s ok – no one knows that the current version worked in the first place, so you’re probably fine. That copying is the most liberating part, and it gives you the opportunity to start fresh.

Now that you’ve got a fresh implementation of whatever was in, it’s time to point everything to your new thing. Since you’ve ideally not just moved code from A to B and changed tabs to spaces, you’ll likely spend quite some time here to update invocations, mocks and the general usage of your new component. That’s fine, and it generally can be a rewarding activity.

Phase 3 is the march to the trash bin: You just get rid of the old stuff. Delete it, move it away. As a little guide for myself, I’m trying to half the code – if you’re just beginning that process in your code base, you’ll probably be able to reach that point quite often. More mature code bases might not benefit that much from frequent deletion interventions, but your mileage will vary.

It’s much more liberating for your codebase, for your skills and for the overall quality of what you’re potentially delivering to create a habit of starting new in places that need this level of attention. It’s a super effective muscle, and one that comes with a lot of fun when properly used.

Happy Deleting!