I’ve been told over and over again about importance of writing modular code, that is, code that can be easily extended and reused. Yet, even with this in mind I still sometimes find my self hard-coding things only to wish I hadn’t later down the road.
For instance, today when I was scrolling through the spread sheet that I log all of my hours in for Gridnet, I realized that it’s been almost seven months since I first started work on it. While that is quite a long time, I’ve only logged about a hundred real hours into the project. Regardless, I was curious where all of my time had gone. Luckily, when I started the spread sheet I had decided to keep a column that notes the general things I did on any given day. I found that I had spent most of my time rewriting previous code because I needed to add a new feature that wouldn’t work with the current system. This appeared several times throughout the spread sheet, which is quite saddening.
Obviously, rewriting code wasn’t an ideal way to spend my time; it causes me to lose focus on current goals, break other parts of the game causing bugs, and promoting general unhappiness with the project. I’ve found that the best way to combat this is to always write modular code. Even if I don’t think I’ll need to extend it later, it’s better to invest a few minutes now that waste many hours later.
However, there are occasions where I need to rewrite code. For instance, the purpose of doing an optimization pass on a project is to rewrite inefficient code and replace it with something faster. For the most part though, it doesn’t require too many touch ups unless of course I’ve made some really poor design decisions in the beginning.