What Is ‘Foo’ in Programming?

In Programming, “Foo” means nothing. It’s a placeholder value for when a programmer cannot come up with a better alternative. Value like “Foo” also highlights the fact that the choice of name is not the relevant part of the code example.

You see “Foo” a lot in programming tutorials and lecture slides. Also, if more than one name is necessary, the word “foo” is typically followed by “baz” or “bar”.

How to Use “Foo” in Programming?

When you are working on an example code with sample values, you may have noticed how hard it is to come up with a placeholder name.

This is why programmers typically use “Foo”. This dummy value is easy to remember and throw in the mix out of thin air. Another common dummy value that is widely used by programmers is “bar”. This is useful if you need more than one sample name.

Let’s see when “Foo” can be useful. Here is a Python example that demonstrates how to use F-strings with placeholder values:

val1 = "foo"
val2 = "bar"

print(f"Hello, {val1} {val2}!")


Hello, foo bar!

The whole point of this piece of code is to demonstrate how a Python concept works. Thus, the values it uses don’t matter. This is why the values “foo” and “bar” are used. Also, you don’t want to use names that would draw attention to them. When a programmer sees “foo” or “bar”, they instantly know those are dummy values one can ignore.

Why “Foo”?

The origin of the word “foo” is unclear.

Some suggest the origin of “Foo” comes from the 1930-1950 era in the Smokey Stover comic strip by Bill Holman. This is because the unexplained letters “F-O-O” comically appear on license plates, picture frames, and sandwich board signs.

Another theory for the words “foo” and “bar” is suggested to originate from the World War II era term “FUBAR” which stands for “F***ed up beyond all repair”. This would also explain why the word “bar” is usually used in conjunction with “foo”.

When Not to Use “Foo”?

The variable “foo” is useful when you practice coding skills and play with code examples. Also, if you are running a class, tutorial, or mentoring someone, coming up with short placeholder values like “foo” and “bar” can save you time.

But don’t use values like “foo” or “bar” in actual projects. This is because you want to keep it clean and readable all the time. If you have variables, classes, or methods called “foo” or “bar”, you will have no clue what they are supposed to do. This is especially true if you come back to your projects after a while. Make sure to use descriptive and easy-to-understand names when not playing or demonstrating!


Today you learned what “foo” means in programming.

To take home, “foo” is a dummy name or a placeholder value for the lack of a better name. “Foo” is commonly used in code samples and examples. When one placeholder is not enough, you commonly see the word “bar” used after “foo”.

Using values like “foo” or “bar” is useful when you are playing with code examples or demonstrating code to others. This way you don’t have to waste resources in coming up with a creative name.

Don’t use stupid values like “foo” or “bar” in your real projects, though. Instead, write clean code and give a clear and consistent meaning to variables and other values in your code.

Thanks for reading! Happy coding!

Further Reading