Eric Lippert has written about cargo cult programming, and Steve McConnell has tackled the subject from a Software Engineering point of view.

Eric provides a fairly succinct description:

They understood the form but not the content. There are lots of cargo cult programmers -- programmers who understand what the code does, but not how it does it. Therefore, they cannot make meaningful changes to the program. They tend to proceed by making random changes, testing, and changing again until they manage to come up with something that works.

This isn't to say that cargo cult programmers are bad, per se, just that they approach coding differently than others. Their goal is to get things done; not understand why the code is doing something. This Programmers question discusses formatting and "sloppy programmers", but it's different in that it doesn't focus on whitespace and it's clear the programmers are considered bad.

Much has been written on Programmers about using comments as well as the use of whitespace.

The general acceptance is to use comments to explain "why not what" and to use whitespace to separate out logical constructs within the code. To borrow from traditional writing, whitespace provides paragraphs of text to read instead of facing a wall of text. It separates out key concepts.

I'm in the middle of re-factoring some code originally written by a cargo cult programmer, and one of the challenges I have encountered is consistent lack of whitespace to indicate context or concepts within the program. Looking over the code, it's clear to me the developer didn't understand the why or the context behind the task they were assigned. Ignoring the incorrect copy & paste issues, the code just doesn't read well because of disjointed flow amongst statements.

I realize that use of whitespace is biased by the original language that someone first learns, but I can't help but wonder if "illogical" use of or lack of use of whitespace is an indicator of a cargo cult programmer.

My question: -- Is there a correlation between not using whitespace correctly and the odds of the person being a cargo cult programmer?


I realize my question is subjective, but I think it falls into the good subjective category because this question is best answered with a "why" type answer rooted in experience and / or potentially some amount of research. Likewise, I believe there is an answer to the question, and I have focused the question on identifying if there is a correlation while avoiding any potential ranting.

In my question, I am using the broader definition of cargo cult programming as defined by Eric. Cargo Cult Programmers mix and match forms because the snippet they took appears to solve the problem at hand. Yet they do not understand why the sections they copied resolve the issue. In this context, I don't see Cargo Cult Programming as attempting to imitate another person's style, but rather just trying to "fix" whatever the problem at hand is with whatever code they can find.

closed as primarily opinion-based by Robert Harvey, Bart van Ingen Schenau, gbjbaanb, Dynamic, jwenting May 14 '14 at 7:16

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 13
    It's an indication of inexperience. Cargo-Cult Programming is something else; it's attempting to appear that you know what you're doing by emulating the form of other people's programs, but not the function. Lack of whitespace is not cargo cult, because you're not trying to imitate someone else's good style. It's not even cult, unless he's hanging out with black hats. – Robert Harvey May 13 '14 at 15:55
  • 1
    @RobertHarvey - When someone copies two separate if statements and nests one of them without indentation, it would make me wonder if they knew what they were doing. – JeffO May 13 '14 at 17:53
  • 1
    @JeffO: Yes, that's what I said. :) – Robert Harvey May 13 '14 at 17:57
  • @JeffO some people are just lazy and don't take pride in their work. – gbjbaanb May 13 '14 at 18:46
  • 3
    I work with a lot of highly-educated people who write a lot of programs, but are not software engineers. They are full of what we call bad habits. Sometimes I'm able to nudge them into writing stuff that's readable. It's not a concern that they're used to considering. They tend to smile at us with all our pseudo-religions, but when they have to maintain their own code over years, they start to see the value of indentation, spacing, meaningful names, not using the same variable for multiple pusposes, etc. etc. – Mike Dunlavey May 13 '14 at 19:54
up vote 13 down vote accepted

I would say there's a correlation but not necessarily causation. People who have difficulty understanding the meaning behind a program also tend to have difficulty seeing how whitespace enhances other people's understanding of that meaning.

The same effect is seen in prose. People who have trouble coherently grouping their thoughts also tend to see little value in separating those groupings with paragraphs.

It's possible for technically solid code to be very poorly formatted, but in general you can assume programmers' formatting skills are commensurate with the rest of their programming skills. I've seen a few exceptions, mostly with programmers who have worked alone for many years, or naturally very talented programmers straight out of school.

Whether poorly formatted code confirms a cargo-cult mentality or not doesn't change the result. It makes you trust the code less, so even if you fix the whitespace you will be on the lookout for other problems, instead of believing the code does what it says it does. In other words, if you want your code to be taken seriously, it needs to look nice.

To keep within the story of the Cargo Cult, this would be like someone who writes code that does "Some Amazing Thing" and thinks hoards of programmers will contribute to this open source project even though the code itself is poorly formatted. Everyone else gets tons of contributors and my app is just as amazing as theirs.

How many people will look at this and not even bother? Maybe someone with some time on their hands will put in all the white space and that will get the project some traction. it leaves a lot of doubt about the lead developer. Who knows, maybe this code was copied from somewhere else and put into Word.

There are some who don't think formatting matters especially in "this" case. Good programmers format without even thinking about it, so there isn't even a drop in productivity.

A good carpenter touches a piece of material the fewest number of times as necessary: cut a small piece off a board, throw it in the scrap bin and not on the floor only to have to pick it up and throw it away later.

Not necessarily. As you mentioned, whitespace is biased by their "natural" programming language. However, I've also noticed some developers seem to have some kind of strange aversion to scrolling down to read more code.

I work with a developer who is not a cargo cult programmer, but does use far less whitespace than I find readable (or, if you ask him, would say that I use excessive white space). He codes using vim, often with several windows open for reference as he's working. As a result, he tends to prefer smaller windows, but still wants to be able to see more than a few lines of code in the window. The result is a bare minimum of whitespace in anything he's written.

At my last job, code ran on for as long as it took to type everything, with no line-wrapping whatsoever. Instead, you'd have to constantly scroll to the right to see what all was going on. I'm not sure why, but in every instance the people responsible weren't cargo cult programmers. Personally, I think it speaks more to a lack of style guidelines than it does anything else.

I would not view lack of vertical whitespace as any kind of indication.

I would view excessive (in my opinion) vertical whitespace as an indication that the programmer was not as experienced as he might have thought he was.

Research going back decades demonstrates beyond reasonable doubt that programmer comprehension is limited by what he can see at one glance, without scrolling or turning pages. Once scrolling, or page changing, becomes necessary, programmer comprehension drops dramatically.

This is also why larger monitors are so strongly desirable.

Whitespace is best used very sparingly. If you don't need it, don't throw it in. If you do need it, consider whether reworking/refactoring might not be a better option.

Not the answer you're looking for? Browse other questions tagged or ask your own question.