logo

Common objections to deleting dead code

Every one of them has a better alternative

Joel Clermont
Joel Clermont
2026-03-03

Yesterday I talked about the cost of dead code. Today let's address some common objections I hear when I suggest deleting it.

"What if I need to reference it?"

This is why we use version control tools like git. You can search commit history with git log -S "function_name", assuming you referenced the function name in the commit message.

You can view an old version of a file with git show <commit>:<file>.

The code is never truly gone. It's just not cluttering your working codebase anymore.

"I'll need it again soon"

If it's been commented out more than a day or two, delete it. See the previous argument: You can always get it back from git.

And honestly, if enough time has passed that you're not sure whether you still need it, you probably don't.

"I use this for local dev/testing"

This is the most dangerous objection. The "uncomment, run, re-comment, never commit" workflow is fragile and risky. You might accidentally run it against production data. You might forget to re-comment it before committing.

If you need dev or testing utilities, give them a proper home, like an artisan command, a seeder, or a test. Turn this into something that lives in your codebase intentionally and can be reviewed, tested, and maintained.

Here to help,

Joel

P.S. Lots of good tooling tips and tricks get shared in our community. Come join the conversation.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice.