In computer programming, a metasyntactic variable is a name used in examples and understood by hackers and programmers 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. The use of metasyntactic variables is also helpful in that they free the programmer from having to think up a logically named variable for the topic under discussion.
The phenomenon is similar to the use in algebra of x, y and z for unknown variables, and a, b and c for unknown constants.
Metasyntactic variables are so called because:
However, it has been plausibly suggested that the real reason for the term metasyntactic variable is that it sounds good: the term is a piece of computer jargon.
Foo is the first metasyntactic variable commonly used. It is sometimes combined with bar to make foobar. This suggests that foo may have originated with the World War II slang term fubar, as an acronym for fucked/fouled up beyond all recognition, although the Jargon File makes a pretty good case that foo predates fubar. Foo was also used as a nonsense word in the surrealistic comic strip Smokey Stover that was popular in the 1940s and 1950s. It appears to be unrelated to Kung fu. See also Foo fighter for more foo etymology, as well as RFC 3092.
Bar, the canonical second metasyntactic variable, is a kind of alias, commonly used to represent an as-yet-unspecified term, value, process, function, destination or event, but seldom a person (see Ned Baker, below). Typically follows foo.
baz, the canonical third metasyntactic variable, is commonly used after foo and bar.
Quux is the canonical fourth metasyntactic variable, commonly used after baz. However more recently Qux has become more common as the fourth variable, displacing Quux as the fifth. A probable reason for this is that Quux is often followed by the series Quuux, Quuuux, Quuuuux etc. and Qux fits this pattern perfectly.
Bat is used by some programmers as an alternative to quux.
The word xyzzy is the "magic word" from the Colossal Cave Adventure, and as such is often used as a metasyntactic variable, especially by old-school hackers.
Spam and eggs are the canonical metasyntactic variables used in the Python programming language. This is a reference to a famous comedy sketch by Monty Python, after whom the language is named.
Other words used as metasyntactic variables include: test, mum, thud, beekeeper, hoge, corge, grault, garply, waldo, plugh, kalaa, puppu, dothestuff, temp, var, sub.
The number 42 is often a common initializer for integer variables, and acts as in the same vein as a "metasyntactic value". It is taken from Douglas Adams' The Hitchhiker's Guide to the Galaxy, where Deep Thought concluded that it was The Answer to Life, the Universe, and Everything.
The number 47 is sometimes used instead of 42 above, and is used mainly by members of the 47 society, or New Trek fans.
4711 is most commonly used in German computer speak as a random member of a set. It is a brand of Eau de Cologne, originally named after the number of the manufacturer's house in Cologne.
J. Random and Ned Baker are the names of archetypical users; compare to "The Joneses". J. Random Hacker and J. Random User are also common.
Alice and Bob are names of the archetypal individuals used as examples in discussions of cryptographic protocols. Others include:
Bob, Alice and Carol may have come from the 1969 movie Bob & Carol & Ted & Alice, or from the fact that they are common English names starting with A, B and C, the first letters of the alphabet.
After the characters in the cartoon series The Flintstones.
Sometimes placeholders from other contexts will be used: John Doe, Jane Roe, Richard Roe, A N Other, John Q. Public.
Other languages sometimes have their own metasyntactic variables. For example: