40

I've always wanted to know what the foo, bar, baz, etc... names mean.

Several times I've found these terms in scientific articles. Furthermore this terminology in some way serves as a standard for other exemplifications.

Does anyone know where these terms come from, and how to use them properly?

10
  • 11
    Ask and thy shall recieve; tools.ietf.org/html/rfc3092 Commented Dec 10, 2015 at 21:28
  • 1
    N.B. foo bar, foo baz, are acceptable but do not combine two foos in polite company (NSFW). Commented Dec 10, 2015 at 21:36
  • 6
    Whenever I hear the use of "foo", "bar", or "baz", I lose respect for the presenter. Unlike the compilers of yesteryear that encouraged the use of short variable names (such as a1, a2, and a3) to save space, modern compilers support long and highly descriptive names, so there's little excuse to perpetuate this cryptic, over-used convention. And when you consider the meaning behind the FUBAR acronym, the "foo/bar" similarity IMHO makes its continued citation a crude and immature practice.
    – Jazimov
    Commented May 1, 2017 at 15:02
  • 5
    @Jazimov Of course, the variables shouldn't be used in real code projects, but as variable names for illustration purposes, foo is a much better choice than metasyntactic_variable_whos_exact_identity_is_unimportant. Then again I sometimes enjoy crude and immature jokes -- there's no accounting for taste. Commented Aug 21, 2021 at 14:58
  • 4
    @Jazimov I don't think I quite explained what I meant by "illustration purposes" -- if what's being illustrated has to do with, say, economics, then your examples may be good choices. But what I meant was, when illustrating a general programming concept, a short variable name such as foo can be a good choice, because it doesn't distract from the coding concept you're trying to illustrate. Of course you may argue that one can just use a or something for those situations, which is fair enough; again, a matter of taste. Commented Sep 1, 2021 at 21:43

2 Answers 2

15

While this question borders on being outside the scope of Stack Overflow, I highly recommend the Wikipedia article on the matter:

The History of Foobar

To give a quick preview:

The word foo originated as a nonsense word from the 1930s, the military term FUBAR emerged in the 1940s... 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.

6

The terms foobar (/ˈfuːbɑːr/), foo, bar, baz, and others are used as metasyntactic variables and placeholder names in computer programming or computer-related documentation. They have been used to name entities such as variables, functions, and commands whose exact identity is unimportant and serve only to demonstrate a concept.

Foobar Wikipedia article

tldr;

Foo, bar, and other terms are used as placeholder names to demonstrate a concept. In real life, these values are usually substituted with more meaningful names that fit the context of your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.