What is the history of the use of "foo" and "bar" in source code examples? (2012)
Programmers’ habit of naming placeholder variables “foo,” “bar,” “baz,” and similar terms traces back through mid‑20th‑century hacker culture, with roots in military slang like FUBAR and earlier pop‑culture uses such as the Smoky Stover comic. Contributors link these metasyntactic variables to MIT AI Lab conventions and reference sources like the Jargon File and an April 1st IETF RFC, while noting that some related lore is uncertain or semi‑mythical. Opinions diverge on whether such nonsense names aid clarity—by signaling that meaning is irrelevant—or instead confuse learners who would benefit from more descriptive examples.
Origins and Etymology
- Multiple overlapping origin stories are cited, none conclusively dominant.
- Military links: WWI graffiti “Foo was here” (possibly from “Forward Observation Officer”); WWII slang FUBAR (“fouled/fucked up beyond all repair/recognition/reason”).
- Pop‑culture: the 1930s “Smoky Stover” comic heavily used “foo” and “Foomobile,” and some recount a folklore chain: German “furchtbar” → “foo-bar” joke → FUBAR → programming.
- MIT stories: early AI Lab reports used “foo/bar/baz/quux” as placeholders; one commenter claims “fu” and “bar” were originally used, then “fu” softened to “foo,” but others can’t find archival evidence and call this uncertain.
- An April 1st IETF RFC on “foo” is cited; readers treat it as partly humorous, so its historical claims are viewed cautiously.
Military and Phonetic Alphabet Connections
- NATO phonetic alphabet (alpha, bravo, charlie, …) is noted as another military → technical naming influence; older “Able/Baker/Charlie” system is recalled, including its use in atomic tests Able and Baker.
- Commenters detail non‑NATO phonetic alphabets used by US fire/EMS/law enforcement and mixing of alphabets in practice.
- Discussion touches on NATO naming of Soviet/Russian submarines and on special pronunciations (“niner,” “Quebec”) to reduce mishearing.
Metasyntactic Variables and Variants
- Foo/bar/baz/qux/quux are treated as standard metasyntactic variables, comparable to x/y/z in math.
- Other sequences: quxx, xyzzy/plugh (from Colossal Cave Adventure), gazonk (noted as common in Sweden and in Emacs/Erlang examples), zot (from comics), and personal chains like foo/bar/baz/bing/bang/bong.
- Some enjoy this shared “hacker lore”; others find it dated or opaque.
Pedagogical Debate: For vs. Against “foo/bar”
- Critics:
- Argue foo/bar are meaningless, confusing for beginners and non‑native speakers, and easy to mix up, especially in longer, nontrivial examples.
- Prefer descriptive names (myList, myString), simple letters (a, b, c), or “thing/stuff,” claiming this clarifies what is a variable, function, or type.
- Defenders:
- Say the point is that they mean nothing, preventing readers from over‑focusing on domain details.
- Compare them to lorem ipsum or algebraic x/y, and value their brevity and conventional ordering.
Profanity, Gender, and Historical Norms
- One narrative: as more women entered computing in the 1960s, vulgar “fu” was softened to “foo.”
- Others challenge this as speculative or sexist, arguing women were both over‑protected and subjected to stricter “professional” standards, but there’s no clear evidence this drove the spelling change.
- General consensus: earlier environments were more openly sexist; how that specifically shaped “foo” remains unclear.
Jargon File and Cultural Canon
- The Jargon File is mentioned as key background on foobar and hacker slang, but also criticized as dated, culturally biased, and shaped by a controversial maintainer.
- An earlier “canonical” version is linked; readers note divergences and suggest the need for an updated, more representative lexicon.