(picture)

May 13, 2004

Pulling weeds

Ned Batchelder writes about "pulling weeds" in sourcecode.

One habit I have noticed in truly impassioned gardeners is that they are never idle in their garden. Whenever the opportunity arises, they will pull weeds. They may have headed out to replant, or to prune, or to feed, but while out, if they notice a weed, and they have a free hand, they will pull it.

I'm the same way with code. While pursuing weightier matters, if I notice little things wrong, I will fix them. "Acquire" is misspelled "aquire". Fix it. A Windows-specific call has crept in where a portable one will do. Fix it. A function prototype has been orphaned after its definition has been removed. Fix it. The code formatting conventions aren't being followed. Fix it.

Personally, I really enjoy pulling weeds. It doesn't require much mental effort to walk slowly through a page of code and tidy up the borders, and at the same time it's a really nice way to get more familiar with the garden. Sure, the checkin diffs sometimes look silly (and at some times during a project, it's really important that other people can read difference logs without eyestrain) - so, best pull weeds early in the growing season.

If you ever have the misfortune to take over someone else's tar-pit code -- and who doesn't? -- I strongly recommend you just spend a while pulling weeds before anything else. You'll learn a lot about the structure of what you're working with. When you're done, it'll feel more like home. Then you can bring out the excavators, uproot the ugly shrubs, start some heavy digging.