Some of the most satisfying commits I’ve ever done were the ones where I got to remove a lot of old cruft.
As your codebase grows older, it will accrue technical debt. It comes in many forms, but sometimes the most straightforward cure is to cut the bad parts out.
I’m not talking just about dead code. I’m talking about obsolete code. Obsolete code is code that was there for a reason, but the reason is no longer relevant. They are the appendixes of software – still there, still alive, but apparently not serving any useful function. Cut it out before it gets infected.
There are some simple tricks and practices to keep tabs on obsolete code. One of my favorites is the XXX comment:
// XXX (tag1, tag2): Description
You know, like
// XXX (obsolete): When 2.0 is released, this won't
// be needed anymore.
// XXX (bug): drunk, fix later
It’s easy, flexible, and greppable. If you have a lot of code taking care of backwards compatibility, you’ll want to spend extra attention on making it easy to remove when it becomes obsolete.
Sometimes, grepping won’t help and you have to work harder. To cut out the bad part, you need to shuffle things around, refactor, and build some new pieces. But the feeling of making it better is totally worth the trouble.
Don’t be afraid of deleting obsolete code. If you ever need it back (and I’ll bet you won’t), it’s going to be right there in your version control history, waiting for you to resurrect it. Don’t
#if 0 or comment it out. Remove it. The best code is no code at all. The code is our enemy. Don’t treat the code as an asset. Treat it as a liability.
So… What is going to be your satisfying commit of the day?