Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.


Defining Terms: Copy-and-Paste vs Cargo-Cult

During WWII, in the South Pacific, major sea battles left many sinking cargo ships, whose cargo then floated to neighboring islands. Sufficiently advanced technology is indistinguishable from magic, and the inhabitants of these islands had been barely touched by the events of the 20th century so far, so they took the cargo as signs of gods who should be worshipped. Thus a cargo cult programmer is a person who takes the sample code as the work of a diety, not to be understood and changed but to sit, inviolate, in the code base.

In contrast, copy-and-paste programming is taking a solution for one case and copying it, pasting it, making a small change for the next case, and so on. If there's one line of change in a 20-line copied chunk, this means that there are 19 lines that are duplicated, and if there's a problem, 19 lines that have to be serially debugged and fixed wherever you left them, and you might easily forget many of them. It's better to pull as much as you can to a subroutine so if there's a bug, there is one and only one place you have to go to fix it.

Clearly, two anti-patterns you should try to avoid in your programming life, to be sure, but if you copy code from a website and paste it into your own program, you are not a copy-and-paste programmer. Please respect the distinction.

No comments:

Post a Comment