Some quick Googling turned up the phrase’s usual meaning — “usual” because it’s kind of a squishy reference. Typically, though, “cargo cult coding” refers to grabbing chunks of someone else’s code and plugging it into your own without really understanding the underlying logic and/or code itself. “Cargo cult” originally arose in the South Pacific after WWII, when some remote aboriginal Islanders began building elaborate airplanes and landing strips out of scrap metal and coconut fronds and whatever else was lying about, all in hopes of once again summoning the great metal gods that had descended from the sky during the war, bearing wondrous cargo.
I am struck by the elegance of this metaphor, and how aptly it captures the phenomenon of an inexperienced, or maybe just lazy, programmer copying and pasting someone else’s work. The Islanders had the form down pat: their naive recreations of military planes were often eerily detailed. But, of course, they were made out of junk and couldn’t fly. Because the cargo cult religious dudes mistook the effect for the cause, understanding the form without even beginning to grasp the content. Exactly in the way that a programmer who understands what they want the code to do while lacking the underlying comprehension of how it works.
Just got my new programming keyboard. pic.twitter.com/vHpcaDtoC4
— Daryl (@darylginn) September 29, 2017
I was fortunate to come from a program that explicitly forbade the practice. Our instructor stressed — over and over again, especially as the course progressed and both the material and the projects we were building became increasingly difficult and complex — how important it was to write our own solutions from scratch. Understanding the code you’ve written, he would tell us, is as important as getting your code to work. That actually these are two sides of the same coin.
I believed him, and still do. Learning that way was hard, but it has served its purpose. I might still labor to create mid-level JS apps, but I understand everything in between those curly braces, what it does and why it’s there. But as my own solo projects get even broader in scope and more complex to execute, I’m starting to really understand the copy/paste temptation.
After all, there are situations where libraries just don’t cut it. Or where I am in a big hurry on a deadline and have come face to face with one of the many gaps in my own learning curve. Dropping everything to learn this new thing is so very, verrryyy frustrating. Can’t I just pretty please this one time find an applicable block of JS on Stack Overflow and worry about closing this skill gap later? It’s a tricky equation, with no one “right” answer:
(Experiment || Copy Paste) === (Broken Code && Waste Time || Working Code && No Understand)
Interestingly, as I was mulling over these thoughts, my friend Asa brought up copy and paste programming in a totally different conversation. Asa went through the same boot camp, same instructor, and like me has totally bought into the same… well, whatever the opposite of cargo cult coding would be. The importance of understanding what you’re writing and how it works because you wrote every damn symbol of it. Recently, however, he’s begun to wonder as well.
“If I understand completely what my code is doing and why, _re-using_ some stuff might not be the worst thing in the world,” he wrote. “Maybe not copy/paste exactly, but what feels like copy and paste to us.”
I realized I had been starting to feel the same way: Maybe always coding from scratch is a little overrated. And — furthermore — not realistic at this point in our respective careers. This is tricky territory, for sure — we were both taught firmly otherwise, and neither one of us wants to cheat our way to success. But still.
So now I’m wondering: can cargo culting ever be used for good, rather than evil? Blind copying and pasting, the bad way, is usually accompanied by a fervent wish of please God let this work. Because wishing is all you got since if your, um, borrowed code does not actually work chances are you won’t be able to figure out why.
Here is where I am leaning: used responsibly, and from a position of knowledgeable understanding, cargo culting saves us from the need to know absolutely everything all the time. In fact, when used well, it’s the equivalent of drawing upon the expertise of those who have gone before to already solve that problem. If I can see what they did, understand why they did it (and change the variable and function names to appropriately reflect my own purposes, not to mention test everything six ways from Sunday), maybe it’s not inherently evil to follow their lead?
Lordy. I may have just rationalized my way into joining the cargo cult. Well, as practices go, it sure beats waving a live chicken over your laptop.
Feature image via Pixabay.