Day 4 - Excise some unused code

Let’s track down some code that’s not actually in use (and delete it, naturally).

Those of you with statically-compiled languages will probably have little to do today, but in dynamic languages like Ruby and JavaScript, it’s pretty easy to end up with unused code laying around.

To track down your unused code, I recommend a tool like unused : . I’ve personally used it to good effect in Ruby, and I believe it will work well with JavaScript and Elixir (see the docs).

If you have a different method for finding unused code that works well for you, please share it here so others can benefit.

As always, please share your results. I’d love to hear how many lines you manage to excise.

There wasn’t much to remove.

I used the Inspect Code feature. Interestingly it pointed out a couple of areas that are actually needed. And it obviously doesn’t fully understand extensions to the Jest test framework.

That was good exercise!

I’m working with a TypeScript monorepo, and it’s very easy for unused code to stay around when features are removed. unused didn’t cut it, but I finally got the chance to try out ts-prune.

It doesn’t work perfectly with monorepos, but it was simple to use and it helped me detect a dead folder with ~400 LOC. It’s not a big deal, but it makes the code a bit cleaner without all of these little unused files :broom:


Well, I found nothing, either I’m bad using this tool or we have no dead code, but it would be surprising

Done! I was able to remove a bunch of unused methods and properties, as well as a couple of entire files. I had never specifically looked for unused code in a .NET solution before, but I found out that Resharper can do it for you. There is a lot more to work through, but I at least got a good start.

1 Like

Did some yak shaving on the way since I updated the work laptop to Ventura last night so homebrew/Xcode/ctags config fun. Anyway our codebase has so many candidates, but managed to get rid of a dead method from 2007 that was last called anywhere in 2015.

I found some unused code and removed it.

But most importantly, this exercise reminded me how bad meta-programming affects readability, because the unsued tools reported tons of false positives. Some false positives very obvious to me and I ignored them right away. But others were very obscure, and I was happy that my test suite covered those, and I didn’t delete stuff that was actually still in use and called by meta-programming.

I removed some meta-programming that didn’t actually add much value and replaced it with more explicit code to improve readability and maintainability.


I got rid of 500 lines! (Not unused in the sense that it was never referenced, but only called from unreachable branches)

1 Like