Variable "foo" and Other Programming Oddities

If you've ever viewed UNIX documentation, you've probably encountered variables foo and bar at some point. Here's a Ruby example I found in the newsgroups:


This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2005/08/variable-foo-and-other-programming-oddities.html

Years ago, when I first heard of example code making use of the variables Foo and Bar, there were four others, sort of a standard sequence:

foo bar baz eek moof gleep

Nowadays, the only place I can find reference to them is in help files for a multiplayer text game engine called ‘PennMUSH’

This link (a href="http://www.faqs.org/rfcs/rfc3092.html)"http://www.faqs.org/rfcs/rfc3092.html)/a refers to a different sequence:

Foo: First on the standard list of metasyntactic variables used in syntax examples (bar, baz, qux, quux, corge, grault, garply, waldo, fred, plugh, xyzzy, thud).

Plugging my new magic catchphrase ‘metasyntactic variables’ into Wikipedia then sends me off on a long, merry chase into programming nostalgia I don’t think will allow me to get any actual work done today… Among other things, uncovers additional variables without clearly indicating their position in sequence:

bat, shme, spam, eggs, needle, haystack beekeeper, blah, blarg,dothestuff, grault, hoge, kalaa, mum, puppu, sub, temp, test, var, momo

I know I have a lot of free time on my hands, but the author of that Wikipedia article…

FYI, the Ruby sample you picked is not working code - it looks like an example for a proposal for changed block scoping rules.

I was not old enough to be in any of the world wars. but the the word came from the words ‘foo was here’ written on the words of buildings for the advancing soldiers, meaning ‘Forward Observation Officer’. Hope this is another useless piece of trivia you can’t afford to be without.

I personally hate “foo” and “bar”. These are the worst variable and class names for every example, because they have no meaning. I have problems remembering what each “foo” or “bar” does, especially if they use them in every example. You should always use meaningful names, god damn it!

when i dont really care enough about a variable to name it, it gets called LARD.
if i’m stretched to two such variables, the next is called PIES.
(if you need 3 you had better start using meaningful names).

Hermann: you’re missing the point. “foo” or “bar” are intended to be used where there isn’t intended to be any meaning: they signify “anything you want could go here”.

Here’s RFC3092 on the etymology of “foo”:

http://www.ietf.org/rfc/rfc3092.txt

I still use foo but append it with a numeral when more than one foo is required (ex. foo2). i used to use bar until my c++ prof. warned me that (((foo-oo)+u)+bar) == viet-nam.flashback ;

In our super legacy text game code - http://www.ironrealms.com - we have some variables that someone came up with called temp1 and minor1 about 15 years ago.

In those days it was impossible for our code to use anything but global variables. So we had these stupid variables used in a million places throughout all our code. Needless to say it caused endless bug headaches in the games. Anyways, that came to mind when reading about foobar, as I probably would have killed someone if I had ever seen foo or bar used as a variable.