You know what I like more than writing code, or refactoring code, or moving code around? Deleting code - large swaths of it. When I make commits like this…
…My toes curl up inside their shoes a little bit. Writing code is fun, but deleting code is much more satisfying. In fact, deleting code is so much fun that it’s now become part of my regular routine. We want to add another feature? Oh, I’m going to have to delete some of that cruft first. Just like Ripley blasting a flame-thrower at the alien eggs, I like to pull out my editor and make the code run in fear.
You know what’s great about when you get in the habit of deleting code? Your code becomes less sacred - it’s easier to change and be reworked with the shape of your product.
I spent a good portion of this last week pairing with a co-worker on a section of code that’s been in production for quite some time. When you work in a code base for awhile, you become comfortable with the shape of the whole system. Code is the way it is because that’s just the way it is. Does this sound familiar?
We were working on a section of code that needed some performance optimizations, and time and time again he kept asking me why certain sections of code were there.
“What’s this here for?”, he’d ask me.
Sometimes I had an answer, but there were many times when I didn’t. In engineering, “That’s just the way it’s been” as an excuse for keeping a design never cuts it. Ever. If you can’t make a reasonable assertion about why a piece of code exists or you can’t remember what it’s for (and it’s not just that you have a terrible memory), it needs to go. Now.
Delete that crap. Don’t be shy, you’ll feel better once you cut yourself out of the weeds. There’s a simple design lurking somewhere under the jungle brush. When you find it you’ll feel like the air is fresher and the bird songs outside sound sweeter.
Developers like to think of themselves as builders. We wax poetically about craftsmanship, and art and beautiful code and how our editors are akin to a painters paintbrush. I do this all the time - it makes me feel important and special.
Maybe we’re all good at doing the paintbrush thing, but do you know what we all need to get a lot better at? Wielding the machete. If you need an inspirational figure, just think of yourself like Rambo - that guy sure knew what to do with a sharp piece of steel. He was ruthless, just like you should be with some of that nasty code you wrote six months ago.
You cut out the old to make room for the new. The prairie fire allows new growth, and so will cutting out the weeds in your codebase. Seriously, take the time to sharpen up the machete - it was a major highlight of last week for me. It gave me energy and motivation like I hadn’t felt in a long time.