dark mode light mode Search Menu

foo bar baz

Esteban Chiner on Flickr

Take a look at the pseudocode below:

def foo(bar):
      “Happy Birthday “,  bar

Can you guess what the following code will produce: foo(“Eva“)?

Since we replace the word bar with “Eva”, instead of reading “Happy Birthday ”, bar, it will print out Happy Birthday Eva. But what is a foo? How about a bar?

Foo and bar are commonly used placeholders in example code. They are not part of any particular programming language, and can easily be replaced by other names. In the example above, foo is used as the name of a function that takes in a name (such as Eva), and prints out Happy Birthday followed by whatever name was entered. Bar plays the same roll. It is just a placeholder used to stand for whatever name will be entered. Foo and bar (and baz as well) can represent functions, variables, or parameters in example code.

Who thought of such strange names to use in example code? There is a good chance that these words originated in a popular comic series, Smokey Stover, between the 1930s to the 1970s. It is said that the author, Bill Holman, first came across the word Foo on the underside of a statue in San Francisco’s Chinatown. He began using it in nonsense sayings and license plates throughout his comics (in Chinese foo, often spelled fu, means happiness and good fortune). The term foo was most likely popularized in general hacker culture by MIT’s Tech Model Railroad Club, and finally became commonplace in computer science.

Today the terms foo, bar, and baz still pop up fairly frequently when a programmer is using an example to explain a coding concept. Other references to foo, bar, baz include Google’s “secret” coding challenge, Google Foo Bar (can only be entered through invitation), and a well-known annual hacker event, Foo Camp. However, using somewhat nonsensical terms of this sort is not usually the best idea when coding. Take a second look at our original code, in which the function foo and parameter bar, are renamed to better describe their purpose:

def insert_name(name):
      “Happy Birthday “,  name

The function that inserts a name is called insert_name and the name that will be inserted is aptly called name. The mystery of the funny sounds within the code is gone, replaced by a description of what the code does. It is good to be familiar with terms such as foo, bar, and baz as you navigate your way through the world of coding tutorials and explanations, but you will often be better off using more descriptive names when writing your own programs.

Learn More

Google Foobar Challenge




Foo Camp


Metasyntactic Variable