Variable "foo" and Other Programming Oddities

August 28, 2005

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:

foo = 0
bar = 0
1.times do
  foo = 1
  foo := 2
  bar = foo+1
end

puts foo, bar 

O'Reilly's FooCamp ostensibly means "Friends of O'Reilly" but is probably a pun on this same meaningless variable. So why "foo"? I always thought foo and bar were corruptions of the phrase FUBAR, but according to the jargon file, that's not correct:

When ‘foo' is used in connection with ‘bar' it has generally traced to the WWII-era Army slang acronym FUBAR (‘F*cked Up Beyond All Repair' or ‘F*cked Up Beyond All Recognition'), later modified to foobar. Early versions of the Jargon File interpreted this change as a post-war bowdlerization, but it it now seems more likely that FUBAR was itself a derivative of ‘foo' perhaps influenced by German furchtbar (terrible) -- ‘foobar' may actually have been the original form.

For, it seems, the word ‘foo' itself had an immediate prewar history in comic strips and cartoons. The earliest documented uses were in the Smokey Stover comic strip published from about 1930 to about 1952. Bill Holman, the author of the strip, filled it with odd jokes and personal contrivances, including other nonsense phrases such as "Notary Sojac" and "1506 nix nix". The word "foo" frequently appeared on license plates of cars, in nonsense sayings in the background of some frames (such as "He who foos last foos best" or "Many smoke but foo men chew"), and Holman had Smokey say "Where there's foo, there's fire".

Then there are GUI widgets. I know the word predates computers as a generalized business school expression of "some unit of produced goods", eg, from ACME Corporation. But where did the word "widget" come from?

"Widget" is a deliberately invented word meant (probably) to suggest "gadget". Most dictionaries fail to trace it to its origin. It comes from the 1924 play "Beggar on Horseback", by George Kaufman and Marc Connelly. In the play, a young composer gets engaged to the daughter of a rich businessman, and the next part of the play acts out his nightmare of what his life will be like, doing pointless work in a bureaucratic big business. At one point he encounters his father-in-law at work, and we get the following dialogue:

(Father-in-law): Yes, sir! Big business!
Yes. Big business. What business are we in?
Widgets. We're in the widget business.
The widget business?
Yes, sir! I suppose I'm the biggest manufacturer in the world of overhead and underground aerial widgets.

Part of the point, of course, is that no one ever tells him what "widgets" are.

A play, of all things. It certainly must have been popular in the 1920's for this weird little word to catch on; a google search reveals a bunch of hits for recent productions of Beggar on Horseback.

The Beagle Brothers were one of my favorite Apple // software vendors. They had disks chock full of crazy little programs and demos, all written in Applesoft BASIC. In many of these apps the sentence "Pack my box with five dozen liquor jugs" appears. Just more Beagle Brothers zaniness, I thought. Years later, I realized what this phrase actually is. It's a pangram: it uses all 26 letters of the alphabet in a single sentence.

The wikipedia entry notes that pangrams are typically used in font sample apps. That's what launches in Windows when you double-click on a font in the c:\windows\fonts folder. Here are a few examples:

How razorback-jumping frogs can level six piqued gymnasts!Mac, System 7 era
Cozy lummox gives smart squid who asks for job penMac, post-System 7 era
The quick brown fox jumps over the lazy dogWindows, truetype fonts
Pack my box with five dozen liquor jugsBeagle Bros fonts
Jackdaws love my big sphinx of quartzWindows, bitmap fonts

beagle_pack_my_box.png

The pangram Beagle Bros chose is a great expression of their homebrew spirit: it's rather clever and it involves alcohol.

Posted by Jeff Atwood
10 Comments

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...

Eric K. on August 29, 2005 12:00 PM

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

Nathaniel Talbott on August 30, 2005 8:26 AM

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.

John Pot on August 30, 2005 9:59 AM

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!

Hermann Klinke on August 31, 2005 5:31 AM

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).

Mags on September 5, 2005 12:04 PM

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".

Jules on September 12, 2005 12:10 PM

Here's RFC3092 on the etymology of "foo":

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

Jeff Atwood on November 22, 2006 10:49 AM

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 ;

|{urse on March 6, 2008 3:50 AM

I recently came across your post and have been reading along. I thought I would leave my first comment. I wonder how this pertains to Business Loans? I don't know what to say except that it caught my interest and you've provided informative points. I will visit this blog often.
Thank you,
Mazi

Businessloans2010 on April 5, 2010 10:56 PM

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.

Avasyu, the Text Game Ninja on July 25, 2010 12:14 AM

The comments to this entry are closed.