What is the history of the use of "foo" and "bar" in source code examples?

  • Why do many code examples, especially tutorials, use the names "Foo" and "Bar" so often? It is almost a standard.

    For example:

    void foo(char* bar) {
      printf("%s", bar);

    Looks like none of fmsf's posts are safe from RichB's bullying.

    Yup he loves to change what i write, I'm starting to think he is obsessed with it

    the "why foo bar?" title is not very good, IMHO

    I've added an answer with the correct etymology (it's the most popular of a family of WWII US Army slang terms) and my source.

    It's a meme - a communicable idea. It is its own justification.

  • Foo and bar come from the US Army WWII acronym FUBAR, "F-ed Up Beyond All Recognition". A whole family of these terms came into widespread use during the North African and Sicilian campaigns (1942-43). Rick Atkinson's excellent Day of Battle: The War in Sicily and Italy, 1943-1944 gives a list of these. For instance a JANFU is a "Joint Army Navy F Up", such as the incident on 11 July 1943 when the invasion fleet for Operation Husky shot down 23 Army Air Force C-47 transports carrying paratroopers to reinforce the beachhead.

    Update: Wikipedia has a list of related acronyms that includes some the original WWII ones listed by Atkinson.

    Any programmer will understand the motivation for using foo and bar to name variables. They certainly have been part of the C/UNIX culture from the start, and as @Walter Mitty points out, predated it.

    Update (10/5/2009): Here's Atkinson's description:

    Their pervasive "civilianness" made them wary of martial zeal. "We were not romantics filled with cape-and-sword twaddle," wrote John Mason Brown, a Navy Reserve lieutenant headed to Sicily. "The last war was too near for that." Military life inflamed their ironic sensibilities and their skepticism. A single crude acronym that captured the soldier's lowered expectations -- SNAFU, "situation normal, all fucked up" -- had expanded into a vocabulary of GI cynicism: SUSFU (situation unchanged, still fucked up); FUMTU (fucked up more than usual); JANFU (joint Army-Navy fuck-up); JAAFU (joint Anglo-American fuck-up); FUAFUP (fucked up and fucked up proper); and FUBAR (fucked up beyond all recognition) [Atkinson, p. 36].

    Update (11/23/2011): @Hugo has a fantastic list of the non-military antecedents.

    To add to the etymology: "FUBAR may have been influenced by the German word furchtbar, meaning terrible. It is pronounced with a soft cht, and probably made the transition during World War II"

    @Mark, The German Wikipedia (de.wikipedia.org/wiki/Fubar), suggests this might be a pseudoetymology. It also points to antecedents like the "SILENCE IS FOO" sign in Warner Brother's 1938 cartoon "The Daffy Doc".

    @Jim Ferrans: While FUBAR probably influenced the use of "bar" with "foo", there is strong evidence that "foo" by itself well predates WWII, with references at least back to the 1930s, as your comment indicates. It might be good to mention that in the body of your answer.

    Yes, foo definitely predates WWII. In fact, I've found an MIT newspaper piece from 1938 that tells us how common it was: "As an expletive, of course, "foo!" has a definite and probably irreplaceable position in our language, although we fear that the excessive use to which it is currently subjected may well result in its falling into an early (and, alas, a dark) oblivion." See my answer for more and a 1937 reference in the same newspaper: http://programmers.stackexchange.com/questions/69788/using-foo-and-bar-in-examples/80609#80609

  • I think it's the phonetic pronouncation of fubar.

    Which stands for:

    • F*cked
    • Up
    • Beyond
    • All
    • Repair

    Repair or Recognition ;P

    "Fouled" is often used when needing to be polite.

    repair? nah .. recognition

    Sometimes "Fouled Up Beyond All Recovery" (Or f*cked)

    It's "recognition". See quote from Rick Atkinson's Day of Battle here: http://stackoverflow.com/questions/262271/where-did-foo-and-bar-come-from/934884#934884

    Just a note that there's strong evidence (see RFC 3092, the Jargon File, and other answers here) that "foo" was used as a placeholder nonsense word in the 1930s, well before FUBAR came into military slang in the WWII era.

    -1 It's been proven that "foo" and "bar" (and "baz") used in programming exampels have nothing whatsoever to do with the military term FUBAR.

  • The New Hacker's Dictionary has a very good entry on this - and I consider it to be a better resource for this kind of thing than Wikipedia:

    metasyntactic variable /n./

    A name used in examples and understood to stand for whatever thing is under discussion, or any random member of a class of things under discussion. The word foo is the canonical example. To avoid confusion, hackers never (well, hardly ever) use `foo' or other words like it as permanent names for anything. In filenames, a common convention is that any filename beginning with a metasyntactic-variable name is a scratch file that may be deleted at any time.

    To some extent, the list of one's preferred metasyntactic variables is a cultural signature. They occur both in series (used for related groups of variables or objects) and as singletons. Here are a few common signatures:

    foo, bar, baz, quux, quuux, quuuux...:
    MIT/Stanford usage, now found everywhere (thanks largely to early versions of this lexicon!). At MIT (but not at Stanford), baz dropped out of use for a while in the 1970s and '80s. A common recent mutation of this sequence inserts qux before quux.

    bazola, ztesch:
    Stanford (from mid-'70s on).

    foo, bar, thud, grunt:
    This series was popular at CMU. Other CMU-associated variables include gorp.

    foo, bar, fum:
    This series is reported to be common at XEROX PARC.

    fred, barney:
    See the entry for fred. These tend to be Britishisms.

    corge, grault, flarp:
    Popular at Rutgers University and among GOSMACS hackers.

    zxc, spqr, wombat:
    Cambridge University (England).

    Berkeley, GeoWorks, Ingres. Pronounced /shme/ with a short /e/.

    Brown University, early 1970s.

    foo, bar, zot
    Helsinki University of Technology, Finland.

    blarg, wibble
    New Zealand.

    toto, titi, tata, tutu

    pippo, pluto, paperino
    Italy. Pippo /pee'po/ and Paperino /pa-per-ee'-no/ are the Italian names for Goofy and Donald Duck.

    aap, noot, mies
    The Netherlands. These are the first words a child used to learn to spell on a Dutch spelling board.

    Of all these, only 'foo' and 'bar' are universal (and baz nearly so). The compounds foobar and `foobaz' also enjoy very wide currency.

    Some jargon terms are also used as metasyntactic names; barf and mumble, for example. See also Commonwealth Hackish for discussion of numerous metasyntactic variables found in Great Britain and the Commonwealth.

    Have to say, I'm from NZ and I've never heard of 'blarg' OR 'wibble'.

    That was one pretty good. It's elaborate.Thanks dude.

    OMG, my QL account is qux. Shocked...

    @Colin - I altered the link to a different site, since the existing one was offline.

    I found some other interesting metasyntactic variables from an MIT 1964 paper about LISP (that of course also had foo): chi / boston new york / spinach butter steak / foo crock glitch / poot toop / toot toot / isthisatrivialexcercise / ploop flot top / snap crackle pop / one two three / plane sub thresher. See my answer for more info: http://programmers.stackexchange.com/questions/69788/using-foo-and-bar-in-examples/80609#80609

  • Wikipedia gives this definition of Metasyntactic Variable :

    In computer science, programmers use metasyntactic variables to describe a placeholder name or an alias term commonly used to denote the subject matter under discussion or an arbitrary member of a class of things under discussion. The use of a metasyntactic variable is helpful in freeing a programmer from creating a logically named variable, which is often useful when creating or teaching examples of an algorithm. The word foo is the principal example.
    The term "metasyntactic variable" is primarily found in informal literature. It is sometimes also used as a synonym for metavariable.
    Any symbol or word which does not violate the rules of the language can be used as a metasyntactic variable, but nonsense words are commonly used. The same concept is employed in other fields where it is expressed by terms such as schematic variable (see logical form).
    By mathematical analogy: A metasyntactic variable is a word that is a variable for other words, just as in algebra letters are used as variables for numbers.

    The article also gives common examples of such variables in different programming languages :

    In the following example of the C programming language the function name foo and the variable name bar are both metasyntactic variables. Lines beginning with // are comments.

    // The function named foo
    int foo(void)
       // Declare the variable bar and set the value to 1
       int bar = 1;
       return bar;


    Spam, ham, and eggs are the principal metasyntactic variables used in the Python programming language.[5] This is a reference to the famous comedy sketch, Spam, by Monty Python, the eponym of the language.[6] In the following example spam, ham, and eggs are metasyntactic variables and lines beginning with # are comments.

    # Define a function named spam
    def spam():
        # define the variable ham
        ham = "Hello World!"
        #define the variable eggs
        eggs = 1


    In the following example the baz, foo, and bar are metasyntactic variables and lines beginning with # are comments.

    # Declare the variable foo and set equal to 1
    foo = 1
    # Declare the variable bar and set equal to 2
    bar = 2
    # Declare the method (function) named baz, which prints the text 'Hello world'
    def baz
       puts 'Hello world'
  • Here is wikipedia's answer:

    The terms foobar, foo, bar, and baz, are common placeholder names (also referred to as metasyntactic variables) used in computer programming or computer-related documentation. They are commonly used to represent unknown values, typically when describing a scenario where the purpose of the unknown values are understood, but their precise values are arbitrary and unimportant. The terms can be used to represent any part of a complicated system or idea, including the data, variables, functions, and commands. The words themselves have no meaning in this usage, and are merely logical representations, much like the letters x and y are used in algebra. Foobar is often used alone; foo, bar, and baz are usually used in that order, when multiple entities are needed.

    Foo has entered the English language as a neologism and is considered by many to be the canonical example of a metasyntactic variable.[citation needed] It is used extensively in computer programming examples (sometimes expressed as "for once only") and pseudocode. Eric S. Raymond has called it an "important hackerism" alongside kludge and cruft.[1]


    And from RFC 3092:

    When used in connection with 'bar' it is generally traced to the WW II era Army slang acronym FUBAR ('Fucked Up Beyond All Repair'), later modified to foobar. Early versions of the Jargon File [JARGON] interpreted this change as a post-war bowdlerization, but it now seems more likely that FUBAR was itself a derivative of 'foo' perhaps influenced by German 'furchtbar' (terrible) - 'foobar' may actually have been the original form.

    For, it seems, the word 'foo' itself had an immediate prewar history in comic strips and cartoons. In the 1938 Warner Brothers cartoon directed by Robert Clampett, "The Daffy Doc", a very early version of Daffy Duck holds up a sign saying "SILENCE IS FOO!"...(snip)


    or you could just admit it comes from fubar = '"f" up beyond all recognition'

    @Jonathan Fingland: No it doesn't. (In fact, "foo" probably predates both "foobar" and "FUBAR".) See RFC 3092 and the Jargon File entry for "foo".

    @Daniel, Excellent reference. Added

  • tl;dr

    • "Foo" and "bar" as metasyntactic variables were popularised by MIT and DEC, the first references are in work on LISP and PDP-1 and Project MAC from 1964 onwards.

    • Many of these people were in MIT's Tech Model Railroad Club, where we find the first documented use of "foo" in tech circles in 1959 (and a variant in 1958).

    • Both "foo" and "bar" (and even "baz") were well known in popular culture, especially from Smokey Stover and Pogo comics, which will have been read by many TMRC members.

    • Also, it seems likely the military FUBAR contributed to their popularity.

    The use of lone "foo" as a nonsense word is pretty well documented in popular culture in the early 20th century, as is the military FUBAR. (Some background reading: FOLDOC FOLDOC Jargon File Jargon File Wikipedia RFC3092)

    OK, so let's find some references.

    STOP PRESS! After posting this answer, I discovered this perfect article about "foo" in the Friday 14th January 1938 edition of The Tech ("MIT's oldest and largest newspaper & the first newspaper published on the web"), Volume LVII. No. 57, Price Three Cents:

    On Foo-ism

    The Lounger thinks that this business of Foo-ism has been carried too far by its misguided proponents, and does hereby and forthwith take his stand against its abuse. It may be that there's no foo like an old foo, and we're it, but anyway, a foo and his money are some party. (Voice from the bleachers- "Don't be foo-lish!")

    As an expletive, of course, "foo!" has a definite and probably irreplaceable position in our language, although we fear that the excessive use to which it is currently subjected may well result in its falling into an early (and, alas, a dark) oblivion. We say alas because proper use of the word may result in such happy incidents as the following.

    It was an 8.50 Thermodynamics lecture by Professor Slater in Room 6-120. The professor, having covered the front side of the blackboard, set the handle that operates the lift mechanism, turning meanwhile to the class to continue his discussion. The front board slowly, majestically, lifted itself, revealing the board behind it, and on that board, writ large, the symbols that spelled "FOO"!

    The Tech newspaper, a year earlier, the Letter to the Editor, September 1937:

    By the time the train has reached the station the neophytes are so filled with the stories of the glory of Phi Omicron Omicron, usually referred to as Foo, that they are easy prey.


    It is not that I mind having lost my first four sons to the Grand and Universal Brotherhood of Phi Omicron Omicron, but I do wish that my fifth son, my baby, should at least be warned in advance.

    Hopefully yours,

    Indignant Mother of Five.

    And The Tech in December 1938:

    General trend of thought might be best interpreted from the remarks made at the end of the ballots. One vote said, '"I don't think what I do is any of Pulver's business," while another merely added a curt "Foo."

    The first documented "foo" in tech circles is probably 1959's Dictionary of the TMRC Language:

    FOO: the sacred syllable (FOO MANI PADME HUM); to be spoken only when under inspiration to commune with the Deity. Our first obligation is to keep the Foo Counters turning.

    These are explained at FOLDOC. The dictionary's compiler Pete Samson said in 2005:

    Use of this word at TMRC antedates my coming there. A foo counter could simply have randomly flashing lights, or could be a real counter with an obscure input.

    And from 1996's Jargon File 4.0.0:

    Earlier versions of this lexicon derived 'baz' as a Stanford corruption of bar. However, Pete Samson (compiler of the TMRC lexicon) reports it was already current when he joined TMRC in 1958. He says "It came from "Pogo". Albert the Alligator, when vexed or outraged, would shout 'Bazz Fazz!' or 'Rowrbazzle!' The club layout was said to model the (mythical) New England counties of Rowrfolk and Bassex (Rowrbazzle mingled with (Norfolk/Suffolk/Middlesex/Essex)."

    A year before the TMRC dictionary, 1958's MIT Voo Doo Gazette ("Humor suplement of the MIT Deans' office") (PDF) mentions Foocom, in "The Laws of Murphy and Finagle" by John Banzhaf (an electrical engineering student):

    Further research under a joint Foocom and Anarcom grant expanded the law to be all embracing and universally applicable: If anything can go wrong, it will!

    Also 1964's MIT Voo Doo (PDF) references the TMRC usage:

    Yes! I want to be an instant success and snow customers. Send me a degree in: ...

    • Foo Counters

    • Foo Jung

    But let's remember this question is about code examples, so let's find "foo", "bar" and "foobar" published in code.

    So, Jargon File 4.4.7 says of "foobar":

    Probably originally propagated through DECsystem manuals by Digital Equipment Corporation (DEC) in 1960s and early 1970s; confirmed sightings there go back to 1972.

    The first published reference I can find is from February 1964, but written in June 1963, The Programming Language LISP: its Operation and Applications by Information International, Inc., with many authors, but including Timothy P. Hart and Michael Levin:

    Thus, since "FOO" is a name for itself, "COMITRIN" will treat both "FOO" and "(FOO)" in exactly the same way.

    Also includes other metasyntactic variables such as: FOO CROCK GLITCH / POOT TOOR / ON YOU / SNAP CRACKLE POP / X Y Z

    I expect this is much the same as this next reference of "foo" from MIT's Project MAC in January 1964's AIM-064, or LISP Exercises by Timothy P. Hart and Michael Levin:

    car[((FOO . CROCK) . GLITCH)]


    For both "foo" and "bar" together, the earliest reference I could find is from MIT's Project MAC in June 1966's AIM-098, or PDP-6 LISP by none other than Peter Samson:

    EXPLODE, like PRIN1, inserts slashes, so (EXPLODE (QUOTE FOO/ BAR)) PRIN1's as (F O O // / B A R) or PRINC's as (F O O / B A R).

    Some more recallations.

    @Walter Mitty recalled on this site in 2008:

    I second the jargon file regarding Foo Bar. I can trace it back at least to 1963, and PDP-1 serial number 2, which was on the second floor of Building 26 at MIT. Foo and Foo Bar were used there, and after 1964 at the PDP-6 room at project MAC.

    John V. Everett recalls in 1996:

    When I joined DEC in 1966, foobar was already being commonly used as a throw-away file name. I believe fubar became foobar because the PDP-6 supported six character names, although I always assumed the term migrated to DEC from MIT. There were many MIT types at DEC in those days, some of whom had worked with the 7090/7094 CTSS. Since the 709x was also a 36 bit machine, foobar may have been used as a common file name there.

    Foo and bar were also commonly used as file extensions. Since the text editors of the day operated on an input file and produced an output file, it was common to edit from a .foo file to a .bar file, and back again.

    It was also common to use foo to fill a buffer when editing with TECO. The text string to exactly fill one disk block was IFOO$HXA127GA$$. Almost all of the PDP-6/10 programmers I worked with used this same command string.

    Daniel P. B. Smith in 1998:

    Dick Gruen had a device in his dorm room, the usual assemblage of B-battery, resistors, capacitors, and NE-2 neon tubes, which he called a "foo counter." This would have been circa 1964 or so.

    Robert Schuldenfrei in 1996:

    The use of FOO and BAR as example variable names goes back at least to 1964 and the IBM 7070. This too may be older, but that is where I first saw it. This was in Assembler. What would be the FORTRAN integer equivalent? IFOO and IBAR?

    Paul M. Wexelblat in 1992:

    The earliest PDP-1 Assembler used two characters for symbols (18 bit machine) programmers always left a few words as patch space to fix problems. (Jump to patch space, do new code, jump back) That space conventionally was named FU: which stood for Fxxx Up, the place where you fixed Fxxx Ups. When spoken, it was known as FU space. Later Assemblers ( e.g. MIDAS allowed three char tags so FU became FOO, and as ALL PDP-1 programmers will tell you that was FOO space.

    Bruce B. Reynolds in 1996:

    On the IBM side of FOO(FU)BAR is the use of the BAR side as Base Address Register; in the middle 1970's CICS programmers had to worry out the various xxxBARs...I think one of those was FRACTBAR...

    Here's a straight IBM "BAR" from 1955.

    Other early references:

    I haven't been able to find any references to foo bar as "inverted foo signal" as suggested in RFC3092 and elsewhere.

    Here are a some of even earlier F00s but I think they're coincidences/false positives:

  • using words like "foo" and "bar" make you focus on the concept not on what you can grasp based on the terms you know. For example:

    public abstract class Animal
        public abstract void speak();
    public class Cat 
        extends Animal
        public abstract void speak()
    public class Dog
        extends Animal
        public abstract void speak()

    The above code lets you fall back on your knowledge of real world things.

    If you are trying to explain a concept where the important part is not what is being done (printing meow or bark for example) but on how it is being done then removing the parts that you are familiar help:

    public abstract class Foo
        public abstract void star();
    public class Bar
        extends Foo
        public abstract void star()
    public class Car
        extends Foo
        public abstract void star()

    Now you have to focus on what is really happening, you are no longer able to guess at what is going to happen.

    So, the short version is, that foo, bar, and the like, are used to stress concepts where the content doesn't really matter but the idea does.

    ah, a real answer!

    Yes, but why Foo and Bar specifically? Why not Lorum and Ipsum?

    @TofuBeer Yep, they're "metasyntactic variables". @masher see my answer with loads of references as to why Foo and Bar and not Lorem and Ipsum. http://programmers.stackexchange.com/questions/69788/using-foo-and-bar-in-examples/80609#80609 In fact, there are loads of different metasyntactic variables that have been used over the years, and in different places.

  • From http://en.wikipedia.org/wiki/Foobar

    In technology, the word was probably originally propagated through system manuals by Digital Equipment Corporation in 1960s and early 1970s. Another possibility is that foobar evolved from electronics, as an inverted foo signal. This is because if a digital signal is active low (so a negative or zero-voltage condition represents a "1") then a horizontal bar is commonly placed over the signal label. The Jargon File makes a case that foo possibly predates FUBAR

    this does not explain the why

    I've found plenty of references of first "foo" and later "bar" from MIT and also DEC (both in Massachusetts), in their work on LISP and the PDP-1 and Project MAC from 1964 onwards. It's a nice idea, but I couldn't find any reference to an "inverted foo signal". More here: http://programmers.stackexchange.com/questions/69788/using-foo-and-bar-in-examples/80609#80609

  • From the Jargon Files http://www.catb.org/jargon/html/F/foo.html

    foo: /foo/

    1. interj. Term of disgust.
    2. [very common] Used very generally as a sample name for absolutely anything, esp. programs and files (esp. scratch files).
    3. First on the standard list of metasyntactic variables used in syntax examples. See also bar, baz, qux, quux, garply, waldo, fred, plugh, xyzzy, thud.

    bar: /bar/, n.

    1. [very common] The second metasyntactic variable, after foo and before baz. “Suppose we have two functions: FOO and BAR. FOO calls BAR....”
    2. Often appended to foo to produce foobar.
  • According to http://en.wikipedia.org/wiki/Foo:

    The terms' origins are not known with certainty, and several anecdotal theories have been advanced to identify them. Foobar may derive from the vulgar military acronym FUBAR, or it may have gained popularity due to the fact that it is pronounced the same.

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM