Metasyntactic variable foo
February 29th, 2008
As you know the term foobar or foo and bar separately are very often used in programming examples.
const Object* foo(); void bar(Object *); void blah() { bar(foo()); // Error: bar discards const };
You might have known that spam and eggs are variables most commonly used by Python programmers.
The majority of programmers might be aware of those variables being called metasyntactic variables but I think just a few do exactly know where they come from, what can be attributed to the fact that this question may is not be answered conclusively.
A very historic example of foobar being used in a famous program is its use as a variable name in the fortran code of Colossal Cave Adventure (1977). The variable FOOBAR was used to contain the players progress in saying the magic phrase “Fee Fie Foe Foo”.

The first appearance of FOO can be found in 1930 in a comic strip called “Smokey Stover” (www.smokey-stover.com). In this connection, the autor makes BAR a word for the military abbreviation “FUBAR”, which stands for “Fucked Up Beyond All Repair” or “All Recognition” - in other words “irreparable”.
Earlier versions of this entry suggested the possibility that hacker usage actually sprang from “FOO, Lampoons and Parody”, the title of a comic book first issued in September 1958, a joint project of Charles and Robert Crumb. Though Robert Crumb (then in his mid-teens) later became one of the most important and influential artists in underground comics, this venture was hardly a success; indeed, the brothers later burned most of the existing copies in disgust. The title FOO was featured in large letters on the front cover.
Other sources confirm that FOO was a semi-legendary subject of British-army in World War II graffiti more-or-less equivalent to the American Kilroy. Where British troops went, the graffiti “FOO was here” or something similar showed up. Several slang dictionaries aver that FOO probably came from Forward Observation Officer.
The question is if foo is used just in any case you just like to or if there are some kinda rules or unified standards when it should be used and when not.
The first usage is simply the one mentioned above in source code. Additionally in filenames, a common convention is that any filename beginning with a metasyntactic-variable name to mark it as a file that is crap and may be deleted at any time.
The etymology of hackish foo is obscure. In RFC (Request for Comments) documents yuo can find comprehensive information about the Etymology of “Foo” (RFC 3092). The document is 99% fun and shouldn’t be taken too seriously. It’s awesome that people put in so much effort for a really unimportant variable that’s not really more than a placeholder in code.
For me the the only sense in foo is to have a variable that doesn’t prescind from the major thing in the example. Besides you don’t have to think every time again of a variable name that is elevant to contribute. Even thought I can’t remeber of having used foo or bar lots of times.





