Where Do Foo, Bar, and Baz Come From in Programming?

Where Do Foo, Bar, and Baz Come From in Programming? Featured Image

Software development (and learning to code in general) tends to be a frustrating process. After sifting through tutorial after tutorial, you’re almost certain to bump into a few terms that live in infamy in the field: “foo” and “bar.” Today, I’ll quickly share their history as well as some perspectives with folks who are still holding onto them.

Table of Contents

Modern Usage

If you’ve looked at any programming tutorials online, there’s an incredibly high chance that you’ve seen variables with strange names like “foo” and “bar.” No doubt these are terrible variable names, yet you’ll still see them all over the place.

In my case, I most recently saw “foo” being used in a practice exam for a course I teach. The choice of “foo” was deliberately meant to obscure the purpose of a piece of code as students were expected to figure it out without context clues (like variable names). Regardless, many students asked me “what the heck is foo?”

After seeing my students just as confused as I was the first time I saw it, I figured I’d share my best guess at the origins of the terms as well as what other folks have said around the internet.

A Borrowed Phrase?

Most of the time when you see “foo” in a tutorial, “bar” is not far behind. When slapped together, you get “foobar,” which is awfully similar to the phrase: fubar (i.e., fucked up beyond all recognition). In other words, the use of “foo” and “bar” seems like a clever joke hidden in code (i.e., this code is junk). Interesting to see it then in educational materials.

Regardless, the connection between “foobar” and “fubar” turns out to have some truth—at least according to Jim FerransOpens in a new tab.. But is that the whole story?

According to some other folks, “foo” might actually predate “fubar,” with evidence pointing back to the 1930s or earlier. In fact, RFC, which tracks various technical documents, has a document that covers the etymology of “foo.” In their documentOpens in a new tab., they argue that “fubar” may only have influenced the popularity of “foobar” and that “foobar” may even be the original term. Specifically, they point to a variety of comics and cartoons that contain the term “foo” prior to World War 2.

And, RFC aren’t the only keepers of knowledge. Another user, known as HugoOpens in a new tab., shared some resources that refer to the term “foo” from 1930s university documents.

Should We Continue to Use Foo?

Having gone through the existing literature on the origins of “foobar,” I don’t think this is a subject that I can really contribute to in a meaningful way. As a result, I’ll share what I think is the best reference for learning more about the history of these terms (i.e., RFC3092Opens in a new tab.).

Instead, I want to take a moment to reflect on “foo” and it’s use in modern tutorials. Given the fact that most folks who see and use “foo” have no understanding of it’s origins, it’s probably time to let the term die out. While its intended use is as a throwaway placeholder, most folks just find it more confusing. Instead, I might advocate for being more explicit when making placeholders—like literally using the term “placeholder.” And certainly I’m not the only one who hates its use:

Although, be careful in some of those posts above. A lot of folks seem to really love “foo” and “bar.”

At any rate, that’s about all I had time for today. It’s the holidays after all, and I should probably be spending time with my family. Of course, if you’re reading this with some free time, check out some of these related posts:

Otherwise, take care! And as always, feel free to help grow the site.

Jeremy Grifski

Jeremy grew up in a small town where he enjoyed playing soccer and video games, practicing taekwondo, and trading Pokémon cards. Once out of the nest, he pursued a Bachelors in Computer Engineering with a minor in Game Design. After college, he spent about two years writing software for a major engineering company. Then, he earned a master's in Computer Science and Engineering. Today, he pursues a PhD in Engineering Education in order to ultimately land a teaching gig. In his spare time, Jeremy enjoys spending time with his wife, playing Overwatch and Phantasy Star Online 2, practicing trombone, watching Penguins hockey, and traveling the world.

Recent Posts