Cookin' Code
My wife and I have done our share of cooking, me as a short order chef and she as someone who just enjoys it. Both of us are a “clean as you go” type of chef (loosely speaking here). My friend has the attitude that if I cook it, you clean it. We can all create good food after our style, but the state of the kitchen and the ability to do more is very different by the time we are done. By the time my wife and I are done, the used dishes are either in the sink or the dishwasher and the surfaces are wiped clean. By the time my friend is done, it looks as if hurricane Katrina had her way with the kitchen. Either way, there is some finish work that needs to happen but the amount of work is drastically different.
There’s a subtle psychological difference and a big difference in the time to completion. If you clean up your code as you go, the effort is much smaller and the number of loose ends are far fewer. If you wait until you are done with a cycle, you’ll end up with several methods that accomplish the same goal with only slight differences. The effort to consolidate them can be pretty heinous. Particularly if you have to adjust the client code to be consistent.
In both cases the underlying philosophy is “make it work, then make it better”. I’ve found that making the cycle shorter between making it work and making it work better keeps the code cleaner. It also makes it done. If you hand a customer a working application, but there are a “few things to clean up” then the customer will only be so patient. A lot of the things you may want to clean up will just not get done because the client doesn’t want to pay for it. They need to be done, and those who need to maintain the app after you will curse under their breath if they aren’t done—but it’s a hard sell. What’s worse is that the time to clean up becomes longer than if you’ve been cleaning as you go. There’s no baked on grease, or staining things that have been left on the cooking surface too long.
Keep things simple, and keep them clean as you develop. Create your test proving you have work to do, make the test pass, then make the code cleaner. You’ll find that not only does it make it easier to move on to the next thing, but you end up working quicker overall. It takes me about the same time to clean as I go as it does to “make it work” and not clean as I go. The hacks you did along the way accumulate and dry and harden, and make it generally unpleasant to fix.
