foo bar baz

These three strange words keep popping up in coding tutorials. What’s their story?

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



  • Jennifer Newell

    Jennifer is a math teacher by training, with an interest in computer science. While working on a computational thinking project at Google, she dived a bit deeper into CS education. Jennifer now teaches computer science to both high school and elementary school students, in addition to mathematics.

Also In The August 2019 Issue

Explore the world, spend time with family and friends, and shed some light on the secrets of nature!

Make your sprite’s motion more realistic by adding acceleration and gravity to your code!

These three strange words keep popping up in coding tutorials. What’s their story?

Interactive play is a great way for students to learn STEM concepts, and new web technologies are making this easier than ever.

Meet the STEAM star who’s combining activism, innovation, and collaboration to build a better world — with sparkles!

Eating dog food doesn't sound like much fun but it's an important part of creating software.

Transform ordinary smiling faces into something kooky and unique with this fun SketchUp activity.

Learn what your antivirus software does, and why it’s important to keep it updated.

Driverless cars could mean less traffic and less accidents, but their developers have some challenges to solve.

A long time ago, before the internet, games were stored on cassette tapes — just like music! Well, Sort of.

We might think robots are a modern invention. But al-Jazari created amazing automatons in the thirteenth century. Today we would call him a maker.

Why does your computer need special hardware to render graphics? And what’s the deal with all those pixels, anyways?

A quick primer to the ins and outs of typed vs untyped programming languages.

Links from the bottom of all the August 2019 articles, collected in one place for you to print, share, or bookmark.

Interesting stories about computer science, software programming, and technology for August 2019.

Interested but not ready to subscribe? Sign-up for our free monthly email newsletter with curated site content and a new issue email announcement that we send every two months.

No, thanks!