Cargo Cult Programming

October 13, 2004 3:25 PM

During World War Two, a number of Pacific islands that had previously been left undisturbed by civilisation found themselves home to military bases. These bases had airstrips on which landed planes full of clothing, food, and all the other things you need to run an outpost.

After the war, the bases were vacated and dismantled, leaving behind a lot of bemused islanders. When the strange people were around doing strange things, food fell from the sky. When they left, it stopped.

So some islanders began to mimic the activities of the soldiers who had left. They sat in towers, carved new equipment out of wood, lit signal fires, and waited for the food to fall again. Anthropologists dubbed these religious activities "cargo cults". (Wikipedia)

Sometimes, I find myself performing cargo cult programming1.

A piece of code works. I don't really understand how it works or what it's doing. But if I copy it over here, tweak the edges and poke it a few times, I'm pretty sure I can get it doing what I want it to do well enough that I don't have to know how it works.

I'm not really programming, I'm just standing on someone else's runway waving a torch, hoping it'll work.

You don't need me to tell you that this is a Really Bad Thing. The resulting code is error-prone, brittle, inefficient, and don't even think about trying to remove duplication or foster reuse.

That said, sometimes you have a task that's about important enough to deserve an hour's work, but that would take a day to understand. You can either abandon the task as unscheduleable, or you can cargo-cult it. "So long as you understand you don't know what you're doing", I tell myself with a knowing wink. "It will be fine."

This explains how I could have spent the last year on a project that uses Maven, written several build targets (and a tool to build and test against multiple databases and application servers), and still have no real clue how Maven works.

1 This is related to cargo cult software engineering, but not the same since I'm talking about code, not process.

Previously: Close to a Legend

Next: No Swap for You!