
The use of foo, bar, and baz in programming and technical documentation comes from a long history of placeholder names and has its roots in both military slang and early computing culture.
Origins: Military Slang and “FUBAR”
The term foo is believed to have originated from “FUBAR”, a military slang term used during World War II, meaning:
- Fouled (or a more explicit version) Up Beyond All Recognition.
The word foo appeared in various wartime cartoons and comics, particularly in Bill Holman’s “Smokey Stover”, a comic strip that frequently used the phrase “Foo!” in a nonsensical manner. This may have contributed to the term being absorbed into programming culture.
Introduction to Programming
As computing developed in the 1950s and 1960s, early programmers needed generic placeholder names for variables, functions, and other identifiers. They borrowed foo from its military slang origins, and it became widely used in programming books and examples.
From foo, additional placeholder names followed:
- bar (probably because it sounds like “foobar”)
- baz (continuing the pattern)
- qux, quux, corge, grault (less common, but sometimes used)
Usage in Programming
These names are used as placeholders when demonstrating code structure without focusing on specific variable names. They serve the same function as “John Doe” in legal documents or “Acme Corp.” in business examples.
Example:
def foo(x):
return x * 2
result = foo(5) # foo is a generic function name, used for example purposes
Why Not Use Real Words?
- Avoids distraction: Readers focus on the structure of the example rather than interpreting a real-world meaning.
- Universality: Programmers worldwide recognize “foo” and “bar” as generic placeholders.
- Flexibility: They can represent anything—functions, variables, objects—without implying a specific use case.
Conclusion
The tradition of using foo, bar, and baz is an inside joke, a cultural norm, and a practical convention in programming. It helps illustrate abstract concepts in a simple, recognizable way without tying them to real-world terminology.
comments powered by Disqus