What is foo in computer science?
The terms foobar (/ˈfuːbɑr/), fubar, or foo, bar, baz and qux (alternatively, quux) are sometimes used as placeholder names (also referred to as metasyntactic variables) in computer programming or computer-related documentation. They have been used to name entities such as variables, functions, and commands whose purpose is unimportant and serve only to demonstrate a concept. The words themselves have no meaning in this usage. Foobar is sometimes used alone; foo, bar, and baz are sometimes used, when multiple entities are needed.
The usage in computer programming examples and pseudocode varies; in certain circles, it is used extensively, but many prefer descriptive names, while others prefer to use single letters. Eric S. Raymond has called it an “important hackerism” alongside kludge and cruft.
The word foo originated as a nonsense word from the 1930s, the military term FUBAR emerged in the 1940s, and the use of foo in a programming context is generally credited to the Tech Model Railroad Club (TMRC) of M.I.T. from circa 1960. However, the precise relationship of these terms is not known with certainty, and several anecdotal theories have been advanced to identify them.
The etymology of foo is explored in the Internet Engineering Task Force (IETF) RFC 3092, which gives the earliest documented use as being in the 1930s comic Smokey Stover by Bill Holman, where it is used as a nonsense word. Holman states that he used the word due to having seen it on bottom of a jade Chinese figurine in Chinatown, San Francisco, meaning “good luck”. This is presumably as a transliteration of the fu character (fú), which is a common character for fortune, and figurines of the trio of eponymous male “star gods” Fú, Lù, Shòu are common in Chinese communities, as illustrated at right; compare Fu Manchu, fictional character popular in the 1930s. Smokey Stover ran 1935–73, and continued to feature foo prominently, as on the front of the “foomobile” illustrated in the cover at right. The word foo became very popular in the 1930s, and also appeared in other cartoons including the Looney Tunes cartoons of Bob Clampett such as The Daffy Doc and Porky in Wackyland (both 1938, with Daffy Duck and Porky Pig), and in other comic strips such as Pogo.
From there, the Foo migrated into military slang, merged with “FU” of the FUBAR. The term foo fighter was used by Allied aircraft pilots in World War II to describe various UFOs or mysterious aerial phenomena.
The first known use of the terms in print in a programming context appears in a 1965 edition of MIT’s “Tech Engineering News”. Foobar may have come about as a result of the pre-existing “Foo” being conjoined with “bar” an addition borrowed from the military’s FUBAR. The use of foo in hacker and eventually in programming context may have begun in MIT’s Tech Model Railroad Club (TMRC). In the complex model system, there were scram switches located at numerous places around the room that could be thrown if something undesirable was about to occur, such as a train going full-bore at an obstruction. Another feature of the system was a digital clock on the dispatch board. When someone hit a scram switch the clock stopped and the display was replaced with the word “FOO”; at TMRC the scram switches are therefore called “Foo switches”. Because of this, an entry in the 1959 Dictionary of the TMRC Language went something like this: “FOO: The first syllable of the misquoted sacred chant phrase ‘foo mane padme hum.’ Our first obligation is to keep the foo counters turning.” One book describing the MIT train room describes two buttons by the door: labelled foo and bar. These were general purpose buttons and were often re-purposed for whatever fun idea the MIT hackers had at the time, hence the adoption of foo and bar as general purpose variable names. An entry in the “Abridged Dictionary of the TMRC Language” states “Multiflush: stop-all-trains-button. Next best thing to the red door button. Also called FOO. Displays “FOO” on the clock when used.”
The term foobar was propagated through computer science circles in the 1960s and early 1970s by system manuals from Digital Equipment Corporation. Foobar was also used as a variable name in the Fortran code of Colossal Cave Adventure (1977 Crowther and Woods version). The variable FOOBAR was used to contain the player’s progress in saying the magic phrase “Fee Fie Foe Foo”.
$foo is the name of a Perl programming magazine, and Foo Camp is an annual hacker convention.
During the United States v. Microsoft trial, some evidence was presented that Microsoft had tried to use the Web Services Interoperability organization as a means to stifle competition, including e-mails in which top executives including Bill Gates referred to the WS-I using the codename “foo”.
These terms gave the name to foobar2000, an audio player independently developed using C++, as its author was more focused on producing a functional program than on aesthetics.
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:
The Tech newspaper, a year earlier, the Letter to the Editor, September 1937:
And The Tech in December 1938:
The first documented "foo" in tech circles is probably 1959's Dictionary of the TMRC Language:
These are explained at FOLDOC. The dictionary's compiler Pete Samson said in 2005:
And from 1996's Jargon File 4.0.0:
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):
Also 1964's MIT Voo Doo (PDF) references the TMRC usage:
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":
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:
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:
It shares many other metasyntactic variables like: 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
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:
Some more recallations.
@Walter Mitty recalled on this site in 2008:
John V. Everett recalls in 1996:
Daniel P. B. Smith in 1998:
Robert Schuldenfrei in 1996:
Paul M. Wexelblat in 1992:
Bruce B. Reynolds in 1996:
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.
Foo (pronounced FOO) is a term used by programmers as a placeholder for a value that can change, depending on conditions or on information passed to the program. Foo and other words like it are formally known as metasyntactic variables .