What is FooBar?

What is FooBar?

When I started learning Web Development, I came across the terms foo and bar being used in the coding examples. At first, I thought the terms were a part of the code syntax. But after coming across it many times, I somewhat understood that the terms were used for giving examples and were not part of the syntax.

But how does the programming community have a consensus about the use of the two words? and how its use began. I hope this article answers some of your questions.

What exactly is foobar?

The term 'foobar' is, basically, a metasyntactic variable. In computer science, and particularly computer programming, a metasyntactic variable is a specific word or collection of words designated as a placeholder. So, foobar is used as a placeholder for generic examples or temporary files or programs that are to be deleted.

The terms are used when a programmer or a developer has to name a file or part of a code and does not have any name in mind. These metasyntactic variables become convenient in such situations and do not need the programmer/developer to invest his time where it is not necessary.

Other metasyntactic variables are baz, qux, quux, quuz, corge, grault, garply, waldo, fred, plugh, xyzzy, and thud.

Examples

One way, foobar can be used as a placeholder for a temporary file. For instance, foobar.jpg, foobar.svg, etc.

Another way is, where 'foo' is used as the first placeholder and 'bar' is used as the second placeholder of the code. For example,

function foo(bar) {
      return bar;
}

Below is an example of foo and bar used in the C language. The lines beginning with // are comments.

// The function named foo
    int foo(void)
    {
        /* Declare the variable bar 
        and set the value to 1 */
        int bar = 1;
        return bar;
    }

This article on Metasyntactic variable gives common examples of different such variables in other programming languages.

History of foobar

According to an Internet Engineering Task Force RFC, the word FOO started out as a nonsense word, first appearing in Bill Holman's 1930s comic Smokey Stover. Holman says that he used the word after seeing it on the bottom of a jade Chinese figurine in San Francisco Chinatown, purportedly signifying "good luck". If correct, this is presumably related to the Chinese word fu, which can mean happiness or blessing.

During World War II, an acronym FUBAR was popularised which stood for 'F-ed Up Beyond All Recognition'. Also, The German word furchtbar, which means awful, may have influenced FUBAR. It is pronounced with a gentle cht and most likely evolved during World War II. But the words 'foo' and 'bar' predates World War II and is different from its military use.

There is a really well researched answer written by hugo to a question about the history of the word foobar at stack exchange.

I will provide some references here.

  • Mention in the Letter to Editor section of The Tech Newspaper("MIT's oldest and largest newspaper & the first newspaper published on the web") in september 1937.
  • An article about "foo-ism" in the Friday 14th January 1938 edition of The Tech, Volume LVII. No. 57, Price Three Cents.
  • The Tech in December 1938.
  • Probably the first documented "foo" in tech circles - 1959's Dictionary of the TMRC Language.
  • 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).
  • 1964's MIT Voo Doo (PDF) references the TMRC usage.
  • Jargon File 4.4.7 about foobar.
  • A published reference 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.

Read full references from Hugo's answer.

The MIT train room is described in one book as having two "foo" and "bar" buttons at the door. These were general-purpose buttons that were frequently repurposed for whatever amusing notion the MIT hackers had at the time, hence the use of foo and bar as variable names.

Foobar was used as a variable name in the Fortran code of Colossal Cave Adventure (1977 Crowther and Woods version). Intel also used the term foo in their programming documentation in 1978.

References