foo (in software programming)

What is foo in software programming?

Foo (pronounced FOO) is a term used by programmers as a placeholder for a value that can change, depending on conditions or on information passed to the program. Foo and other words like it are formally known as metasyntactic variables.

How foo works in programming

It can be helpful to use metasyntactic variables when creating sample code because programmers don't have to create unique names for each variable value. Nonsense placeholders make it easier to focus on the code's core concept and functional goal.

When defining a template for creating a new user command, for example, the syntax for the command could be written as:

Command foo (arg1, arg2)

The "foo" would mean "the name you give to this command." The "arg1" and "arg2" are arguments or information that will be defined and passed along with the command.

Origins of the term foo

The term foo is not itself unique to the world of programming. The actual origin of the word, however, seems somewhat unclear.

Eric Raymond, author of New Hacker Dictionary, observes that in Bill Holman's comic strip of the 1930-50 era, "Smokey Stover," the letters "F-O-O" commonly appeared, unexplained and as a kind of running gag on license plates, in picture frames and on the backs of sandwich board signs.

There is also evidence that using the term foo derives from the World War II-era phrase FUBAR, as it is not unusual to see "foo" and "bar" both used as metasyntactic variables alongside each other, as shown below:

int max(int foo, int bar)
   int result;
 if (foo > bar)
   result = foo;
   result = bar;
 return result;

Although foo is considered a canonical metasyntactic variable, Raymond notes that these variable names can vary based on geography. He lists quxwaldofredxyzzy, and thud among others that are occasionally used. 

Fredbarney, and wombat seem common in the U.K., while tototatatiti and tutu are reportedly used by the French. Blarg and wibble are often used in New Zealand.

This was last updated in October 2021

Continue Reading About foo (in software programming)

Dig Deeper on Application development and design

Software Quality
Cloud Computing