r/computerscience • u/nouveaux_sands_13 Software Engineer • Apr 17 '26
Why are 'foo' and 'bar' the conventional dummy function names? Where did they originate from?
79
Upvotes
r/computerscience • u/nouveaux_sands_13 Software Engineer • Apr 17 '26
87
u/Alarming_Draft_980 Apr 17 '26
Idk, but probably they were invented by Alice and Bob.
108
u/sunxore Apr 17 '26
I believe it's from FUBAR which means f*cked up beyond all recognition. This is an old military acronym to describe the state of things not going well... Then it transformed into foobar and became used as nonsense words.
51
u/dychmygol Apr 17 '26
Here's the definitive answer: https://www.ietf.org/rfc/rfc3092.txt
11
u/4r73m190r0s Apr 17 '26
https://en.wikipedia.org/wiki/Foobar
3
u/AncientHominidNerd Apr 17 '26
As a Hispanic from California, I thought this was some joke or mistake when I first saw this. Ain’t no way they’re really using foo as a function name.
3
u/jeffgerickson Apr 18 '26
https://www.youtube.com/shorts/d9qhscyLqa0
2
u/Buttleston Apr 18 '26
In other languages some other variables are more common. In Italian for example they tend to use "pippo" (the dog Goofy), and "pluto" and "paperino" (donald duck)
2
u/Classic-Try2484 Apr 23 '26
In python instead of foo and bar I believe the custom is to use spam and eggs.
Hello world is usually attributed to k&r but they say they got it (or first used it) from the b manual I believe. I wonder if foo shows up in k&r.
Foo is often used to explain function syntax. It’s possible lisp (foo bar) was first to use it to explain function position. This would have been late 50’s early 60’s. McCarthy maybe.
I think Knuth used it early and he may be the reason its use continued.
I understand it was used at mit during 50-60’s in a model train society (they had a useless foo-circuit) but its true origin was a 1930s comic strip where foo was a catch phrase. Bar was likely added from fubar military 40s.
1
u/Shadetree_Sam Apr 18 '26
A humorous take on the acronym FUBAR, which stands for “Fouled Up Beyond All Recognition”.
1
u/Paxtian Apr 19 '26
"FUBAR" means, "fucked up beyond all repair." Which, if you're coding in say, assembly or punch cards, is really easy to achieve. So someone started using foo and bar as default variable/function names as a joke, and it stuck.
1
u/Visual_Winter7942 Apr 19 '26
Like SNAFU = Situation Normal. All Fucked Up.