19

I've been here around 4 months and several times I saw that people use foo but I don't know what it means. I would like others to explain me about this variable...

Why is it important? How do I use it? When do I use it? How could I use it?

I read on wikipedia something about Metasyntactic variable, but I don't get what it means.

16
  • 6
    I don't think you can do better than "a placeholder name or an alias term commonly used to denote an arbitrary thing, or an arbitrary member of a class of things under discussion". It's like "this" or "that". Jan 23, 2013 at 22:06
  • This kind of question probably belongs on Stackoverflow. Also it's not related to Linux specifically, or any other OS really.
    – Mark Allen
    Jan 23, 2013 at 22:33
  • 8
    Did you not google your exact question? The second result is exactly your answer.
    – enderland
    Jan 23, 2013 at 23:20
  • 2
    @poz2k4444: I get the first part, there wouldn't be any meaning in having these questions on this site, if there were no use to the larger community. However, I have trouble understanding how this topic can be on-topic here regarding the FAQ. foo is a term strictly used by programmers and in code, and is hard ever related to computer software and hardware from the user perspective.
    – TFM
    Jan 24, 2013 at 16:59
  • 2
    There are many duplicates of this question, and it's really off topic here. See: What does “foo” mean?, What does 'foo' really mean?, What is foo? what is that foo means?, What is the history of the use of “foo” and “bar” in source code examples?, Foobar - Wikipedia — there's not much point in duplicating this one more time by migrating it somewhere else, sorry.
    – slhck
    Jan 24, 2013 at 17:07

8 Answers 8

26

RFC 3092: The Etymology of "Foo" This shows in a drawn out sort of way how Foo was originally to be paired with bar to create foobar (AKA Fubar). These terms are best used for pseudo or fake coding. They are also useful in examples to allow for everyone to follow the variables quite easily. Here is the Wikipedia Link as well!

8
  • 1
    Google is your friend
    – Ryan M
    Jan 23, 2013 at 21:09
  • I tried to google it, but I didn't how to... +1 for the RFC
    – poz2k4444
    Jan 23, 2013 at 21:13
  • 1
    It's all good, luckily people seem to be a lot more relaxed on this site than some of the other stack sites.
    – Ryan M
    Jan 23, 2013 at 21:15
  • 1
    Yeah!! If you explain more your answer I'll choose yours for the RFC reference...
    – poz2k4444
    Jan 23, 2013 at 21:17
  • I just edited it, so we'll see if mine makes the cut! (fingers crossed!)
    – Ryan M
    Jan 23, 2013 at 21:25
7

When someone wants to give a code example, foo is typically used as a way to say "place the actual name of the variable/function/class you will use here".

7

From your linked Wikipedia article:

"metasyntactic variable" is synonymous with "meaningless word"

It's just a nonsense word when you need to name a variable or function but the actual name doesn't matter. Really only used for demonstration of code snippets. NEVER use it in real code.

1
  • The names chosen almost always matter in the actual usage. foo often means "you must choose a name here, and it might matter, and in other places where foo appears in the same example, you have to use the same name."
    – Kaz
    Jan 24, 2013 at 0:06
4

In short, 'foo' and 'bar' are simply placeholders for information you have, such as a username, password, variable, etc.

4

It is the computer equivalent to a dog named "Spot", a cat named "Puss", a man called "John Smith" (no offense to the multitudes out there whose name this really is), or even a fish called "Wanda".

When you want to use a generic name in "computerspeak" you will often use one of foo, bar or baz. Use of foo usually indicates a variable/function/whatever whose name is not important and can be changed. So, if I answer a question on SU using foo as my variable's name, you will know that you can freely change foo to whatever else you feel like.

It is not, as is commonly assumed, an abbreviation of Fie Obfuscating Oenophiles.

3

Metasyntactic variables are variables whose values are understood to be pieces of syntax (possibly, the names of other variables, which are syntax). They appear in formulas that operate on syntax, and so are meta-syntax.

For instance, consider S V O (subject verb object), an expression indicating the basic word order of some human language. These three letters are meta-syntactic variables. Each one denotes some piece of syntax. A sentence subject can be a complex noun phrase, and so on. Moreover, these letters are chosen in a way that is significant in the linguistic problem domain: S stands for subject, and so forth.

foo and bar can be considered metasyntactic in the sense that they serve as place holders for real names that are to be invented by the user. These particular names are meaningful in the problem domain of writing code examples in computer documentation, where they are instantly recognizable, like old friends. So, paradoxically, foo expresses "I am famous for having no meaning. Wherever you see me, replace me with something which has one!", and that is its meaning.

It is also understood that where both foo and bar appear, the user must substitute distinct symbols, and where foo appears more than once in the same example, all occurrences must be consistently replaced with the same identifier.

foo and bar are effective as long as they don't clash with anything in the computer language, such as built-in commands, keywords or the names of significant library functions or variables. If that happens, the syntax and meta-syntax levels become confused. If you're designing a new language, it behooves you to avoid introducing foo and bar as significant identifiers in that language.

The words foo and bar have an etymology, but that etymology is not connected to their meaning in computing documentation.

1
  • Nice explaining in plain english. :) +1
    – John Siu
    Jan 24, 2013 at 0:52
2

It's is practically used just for examples, really ... instead of the variables that you want to use... but if you want to know more... here.. :

FOO:

  Forward Observation Observer.

  FOO Of Oberlin.  An organization whose name is a recursive
  acronym.  Motto: The FOO, the Proud, the FOO.  See
  <http://cs.oberlin.edu/students/jmankoff/FOO/home.html>.

  File Open for Output.

.. Cool question.. And it is very important for the people getting inside all the informatic world, buecuse its an example that is everywhere and if you don't know a thing about nothing, you may fall in an error until you get that foo is an example...

You have different alternatives... but It's part of the same origin of the history!...

Here is the RFC! so check it out. Very usefull for that.

There is also the explanation for bar (it is generally traced to the WW II era Army slang acronym FUBAR ...)

A quick google search may resolve a quick question, look at this wikipedia article:

.. The origins of the terms are not known with certainty, and several anecdotal theories have been advanced to identify them. The first known use of the terms in print appear in a 1965 edition of MIT's "Tech Engineering News." Foobar may have derived from the military acronym FUBAR and gained popularity because it is pronounced the same...

It is interesting and with some info you could use to releave .

Hope it helps!

1

Foo is a variable name used for any sort of variable when the name itself is not important. If you remember math word problems, they would go: Mr Smith has $10 and Mr Jones has $20, If Mr Jones gives Mr Smith $5 how much does Mr. Smith have? Smith and Jones and just names. Foo is similar, it's just a name for a variable because you need a name for the example to make sense.

Not the answer you're looking for? Browse other questions tagged .