36

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?

Ilmari Karonen
  • 49,047
  • 9
  • 93
  • 153
Alvaro Silvino
  • 9,441
  • 12
  • 52
  • 80
  • 8
    Ask and thy shall recieve; https://tools.ietf.org/html/rfc3092 – Henrik Andersson Dec 10 '15 at 21:28
  • 1
    **N.B.** foo bar, foo baz, are acceptable but **do not** combine two foos in polite company (NSFW). – Andrew Morton Dec 10 '15 at 21:36
  • that's awesome!! A rfc!! Thanks! – Alvaro Silvino Dec 10 '15 at 21:37
  • @limelights you can answer the question – Alvaro Silvino Dec 10 '15 at 21:40
  • No, it's fine. It's just a link. If someone else feels compelled but I think we got the answer we deserved. – Henrik Andersson Dec 10 '15 at 21:41
  • 5
    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 May 01 '17 at 15:02
  • 1
    @Jazimov thanks for your input! – Alvaro Silvino May 01 '17 at 19:15
  • 4
    @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. – SpinUp __ A Davis Aug 21 '21 at 14:58
  • @spinup: You don’t need to go from “foo” to a multi-syllabic, multi-word variable name. “Foo” is not a better choice than, say, “interest_rate” or “yield” as “foo” tells you nothing about what’s being illustrated. – Jazimov Aug 21 '21 at 19:56
  • 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. – SpinUp __ A Davis Sep 01 '21 at 21:43

2 Answers2

11

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.

Alex Johnson
  • 1,504
  • 13
  • 20
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.

unrealapex
  • 578
  • 9
  • 23