Cargo cult programming is a style of computer programming characterized by the ritual inclusion of code or program structures that serve no real purpose. Cargo cult programming is symptomatic of a programmer not understanding either a bug they were attempting to solve or the apparent solution. The term cargo cult programmer may apply when an unskilled or novice computer programmercopies some program code from one place to another with little understanding of how it works or whether it is required. Cargo cult programming can also refer to the practice of applying a design pattern or coding style blindly without understanding the reasons behind that design principle. Examples being adding unnecessary comments to self-explanatory code, overzealous adherence to the conventions of a programming paradigm, or adding deletion code for objects that garbage collection automatically collects. Obsessive and redundant checks for null values or testing whether a collection is empty before iterating its values may be a sign of cargo cult programming. Such obsessive checks make the code less readable, and often prevent the output of propererror messages, obscuring the real cause of a misbehaving program.
Origin
The term cargo cult as an idiom, originally referred to aboriginal religions that grew up in the South Pacific after World War II. The practices of these groups centered on building elaborate mock-ups of airplanes and military landing strips in the hope of summoning the god-like airplanes that had brought marvelous cargo during the war. Use of the term in computer programming probably derives from Richard Feynman's characterization of certain practices as cargo cult science. In recent decades, anthropology has distanced itself from the term “cargo cult,” which is now seen as having been reductively applied to a lot of complicated and disparate social and religious movements that arose from the stress and trauma of colonialism, and sought to attain much more varied and amorphous goals—things like self-determination—than material cargo.
A related term in software engineering is cargo cult software engineering, coined by Steve McConnell. McConnell describes software development organizations that attempt to emulate more successful development houses, either by slavishly following a software development process without understanding the reasoning behind it, or by attempting to emulate a commitment-oriented development approach by mandating the long hours and unpaid overtime, while in successful companies these might instead be consequences of high motivation instead of causes of success. In both cases, McConnell contends that competence ultimately determines whether a project succeeds or fails, regardless of the development approach taken; furthermore, he claims that incompetent "impostor organizations" are in fact engaging in what he callscargo cult software engineering.