Why do code examples (mostly tutorials) use the names "Foo" and "Bar" so often? It is almost a standard.

For example:

void foo(char* bar) {
  printf("%s", bar);
+6  A: 


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
+2  A: 

Metasyntactic Variables

-1 for not linking to the canonical source
+5  A: 

From the Jargon Files

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.
+1  A: 

Let me add that it's a cultural thing. In Italy we use other common names for generic variables, files etc.

We commonly use the (italian) names of Disney characters.

+18  A: 

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' andbar' 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.
+2  A: 

I always thought foo bar came from the pronunciation of FUBAR. (F*cked up beyond all reason)


It has the nice side effect of making it obvious to the experienced reader that the given code sample is just an example.

You could see it as a warning agains uncontrolled copy&paste...

+1  A: 

Within the Python community, the right counterparts of foo and bar are spam and eggs.

Federico Ramponi
+5  A: 

Something on the famous phrase : The Jargon File - Foobar. I think it sounds

True. I also think it sounds
+11  A: 

there's an RFC on the matter:

Cool but the document was published on an interesting date ;)
Sixto Saez
@Sixto: Yes, but that's because "foo" is such an "interesting" subject! :-)
Daniel Pryden
+2  A: 

More to the point, Jeff's take.

+42  A: 

I think its 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.
Colonel Sponsz
repair? nah .. recognition
hasen j
Sometimes "Fouled Up Beyond All Recovery" (Or f*cked)
It's "recognition". See quote from Rick Atkinson's Day of Battle here:
Jim Ferrans
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.
Daniel Pryden

People also use baz and quux, which I can't understand at all.

I prefer, if I'm needing more than two trash vars, to use:

snafu, tarfu, fubar, soylent

"It's people" ~)
People (1?) use snafu, tarfu, fubar, and soylent, which I can't understand at all.I prefer, if I'm needing more than two trash vars, to use:baz, quux
@tri situation normal, things are, beyond all recognition, and ITS PEOPLE! SOYLENT GREEN IS PEOPLE!
+3  A: 

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.

Walter Mitty
+3  A: 

RFC 3092: Etymology of "Foo"

+8  A: 

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?
masher could be accurate...

Or in Python, spam and eggs

spam eggs spam spam bacon and spam without spam.bllllllghhhhhh...........
Stefano Borini
so why spam and eggs?
+16  A: 

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)

Daniel A. White
+1 for "citation needed" :P
or you could just admit it comes from fubar = '"f" up beyond all recognition'
Jonathan Fingland
@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 Pryden
@Daniel, Excellent reference. Added
Jonathan Fingland
+6  A: 

It's meaningless, like "widget". It allows you to use a word without worrying about what word to use. See here for more.

For a non-programming use, see Foo Fighter (not the band).

Jon B
+5  A: 

According to

"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."


Look here:

+2  A: 

As far as I know, foo comes from foobar which is an alteration of "fubar", a military catch phraase that stands for "F***ed up beyond all recognition."

Then again, there may be other sources.


Foo and Bar (otherwise known as FUBAR...F***ed Up Beyond All Recognition) has just been used as standard generic names for things like classes, properties, method names, etc.

Basically the idea is to convey your code without as much extraneous information that could possibly get away from how the code works (i.e. we don't need to know your function is named AddUser to see the code and understand what it does if we rename it to Foo() ).


Perhaps Jeff's answer, further linking the jargon file, would be better (as I source checked myself before posting a notional linkage to FUBAR):

Tetsujin no Oni
+2  A: 

Also see April 1st RFC 3092 - Etymology of "Foo".

+23  A: 

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].

Jim Ferrans
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 (, 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
@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.
Daniel Pryden

to make things simple and let you focus on the concepts, of the examples

+1  A: 

Here in Japan many people use "hoge", "piyo" and "fuga" instead of foo bar baz.

Chris B

It came from FUBAR. F'ed up beyond all recognition.