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);
}
|
20
|
Why do code examples (mostly tutorials) use the names "Foo" and "Bar" so often? It is almost a standard. For example:
terminologyexamplesfoobarmetasyntactic-variable
|
|
24
|
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:
|
|
20
accepted
|
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:
|
|
17
|
Here is wikipedia's answer:
http://en.wikipedia.org/wiki/Foo And from RFC 3092:
|
|
8
|
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:
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:
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. |
|
7
|
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). |
|
6
|
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 |
|
6
|
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." |
|
5
|
From the Jargon Files http://www.catb.org/jargon/html/F/foo.html foo: /foo/
bar: /bar/, n.
|
|
3
|
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. |
|
3
|
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. |
|
1
|
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. |
|
1
|
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() ). |
|
1
|
Perhaps Jeff's answer, further linking the jargon file, would be better (as I source checked myself before posting a notional linkage to FUBAR): |