I just love it when I can delete code!

Jim Weirich enthuses about deleting code.

I also love deleting code. In the past month I’ve managed to remove almost 33% of the code from a major work project. It’s been slowly growing in size for over a year, and I’ve managed to get it back to the level it was at in February; although it obviously has much more functionality now.

Much of this was by removing non-obvious duplications (although there were some obvious ones too), removing workarounds for bugs in library code that has since been fixed, and just plain ripping out functionality that’s never actually used. (As much as we like to believe in YAGNI all sorts of things always creep in that seem like they’ll be useful but never actually are, and just turn out to be a complication when you need to extend or modify the code.)

But a large part of it was also finding code that we’d written that we didn’t ever need to, as someone else had already written it. CPAN continues to amaze me more and more every day. Unless you’re working on something really esoteric, 90% of the code you need is probably already available there for you. It’s just a matter of spotting what isn’t really business logic (you usually have much, much more scaffolding than you think), knowing how to find the modules that already provide the functionality, and then gluing it all together.

We were also able to find 3 or 4 things in the code that really weren’t that connected to the actual project, where we would have used a CPAN module if there had been one, rip them out and contribute them back to CPAN. I guess this isn’t really deleting code, but I like to think that it is :)

Leave a Reply

Your email address will not be published. Required fields are marked *