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.

Journeyman Geek
  • 129,178
poz2k4444
  • 904
  • 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". – David Schwartz Jan 23 '13 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 '13 at 22:33
  • @MarkAllen well... I guess so, but since I use this page more often than other, I asked here, anyway it applies for almost everything on IT – poz2k4444 Jan 23 '13 at 22:37
  • 8
    Did you not google your exact question? The second result is exactly your answer. – enderland Jan 23 '13 at 23:20
  • by the way, people use foo as a function name at example code.. because K&R C language uses it first.. – Sungguk Lim Jan 24 '13 at 00:49
  • @enderland I didn't know how to google it, I was not sure... anyway it's cool to have this question in SuperUser, I guess... – poz2k4444 Jan 24 '13 at 02:59
  • @poz2k4444 I literally put your question as asked, here, into Google... – enderland Jan 24 '13 at 03:01
  • @enderland yeah, I didn't think this particular question until I wrote it down, thanks for your comments ;) – poz2k4444 Jan 24 '13 at 03:02
  • @JakeGould That's what "FIXME" is for – Ian Jan 24 '13 at 03:59
  • @JakeGould Haha that's pretty good. I never thought to use FML – Ian Jan 24 '13 at 06:18
  • Anybody care to explain why it should be reopened? – TFM Jan 24 '13 at 06:43
  • @TFM I think it should be reopened because it is a question that could help others who are not native english speakers, as I am, also it is not contrary with the FAQ of the site and it's not a repeated question... I hope it could be reopened... – poz2k4444 Jan 24 '13 at 16:47
  • 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 '13 at 16:59
  • @TFM well... I've seen many questions on this site referencing foo, that's why I asked here, after question this, I checked on StackOverflow and the question is there too, so I don't really know, you guys have more expertise on this site to take decisions, but recalling, Iasked here because I saw it here, and it's something new at least for me and I think many non native english speakers could agree with me... – poz2k4444 Jan 24 '13 at 17:05
  • 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 '13 at 17:07
  • @slhck it's ok, as I said, I just asked because I didn't get the meaning (maybe for not reading well), because it's not in this site, the one which I use the most and for not being native english speaker, but if it stays closed it's ok, just saying... – poz2k4444 Jan 24 '13 at 17:13

8 Answers8

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!

Ryan M
  • 444
  • 1
    Google is your friend – Ryan M Jan 23 '13 at 21:09
  • I tried to google it, but I didn't how to... +1 for the RFC – poz2k4444 Jan 23 '13 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 '13 at 21:15
  • 1
    Yeah!! If you explain more your answer I'll choose yours for the RFC reference... – poz2k4444 Jan 23 '13 at 21:17
  • I just edited it, so we'll see if mine makes the cut! (fingers crossed!) – Ryan M Jan 23 '13 at 21:25
  • best. RFC. ever. – da4 Jan 24 '13 at 01:20
  • I don't know if it's just me, but if I see even basic psuedo code with "foo" and "bar" variables in it I just draw a complete blank and can't understand WTF is going on, and I'm at a complete loss as for the intention of why they're doing it. It turns their concept/demo/example/psuedo code into completely unreadable gibberish. IMHO if you're doing a code example/demo/psuedo code take an extra few seconds and think up a meaningful variable name so the example actually makes sense. – zoszsoz Jan 24 '13 at 01:53
  • I've heard them used in speech when the variables do not need to mean anything. For example, if you're talking about memory access during an assignment, you might say "foo gets bar" to represent myVar = newValue;. Note, for extra geek points you must use baz and quux also. – wjl Jan 24 '13 at 01:56
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".

SethMMorton
  • 368
  • 2
  • 8
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.

techturtle
  • 9,186
  • 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 '13 at 00:06
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.

terdon
  • 53,403
4

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

Primm
  • 221
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.

Kaz
  • 2,691
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!

AAlvz
  • 847
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.

chrisfs
  • 214