Live data from Hacker News

What is the history of the use of "foo" and "bar" in source code examples? (2012)

softwareengineering.stackexchange.com

141–150 of 150 posts

Re: What is the history of the use of "foo" and "bar" in source code examples? (2012)

#141
post #140

Earlier quoted context omitted.

Your argument does make sense for teaching an intro to programming type class, where it may not be obvious what is a function name versus variable name. That just hasn't been my audience for a very long time now when explaining anything. I'd likely also go with var1 var2, fn1 fn2 type names if needing non-descriptive placeholders in that case. I mainly avoid foo and bar because to me it's a tired meme, and people ten…

>Your argument does make sense for teaching an intro to programming type class, where it may not be obvious what is a function name versus variable name. Yea but the truth is a huge of audience of people who are not super familiar with the syntax of a languague will read tutorials describing how to build stuff in that language hoping they can piece things together. So for them it would be helpful. Also, isn't all of…

Oh, sorry that wasn't clear. I meant that type of class, as in, a class similar to "intro to programming", not a class about types in the programming sense. And by "class", I mean classes in the school sense, haha. You're right though.

Re: What is the history of the use of "foo" and "bar" in source code examples? (2012)

#142
post #15

I understand that these variables have a rich and long history, but if you have ever heard a professor or anybody else say "foo" in lecture you will understand why I detest them. They have absolutely no connection to the matter at hand. Since foo is often used before bar, you would think there is an ordering between the two but there doesn't have to be. They are hard to pronounce and easier to confuse. Whenever I giv…

> They have absolutely no connection to the matter at hand. Since foo is often used before bar, you would think there is an ordering between the two but there doesn't have to be. They are hard to pronounce and easier to confuse. I couldn’t disagree more. The entire point is that the variables are disconnected from the matter at hand. They’re widely recognised as placeholders, single syllable, distinctly pronounced fr…

It’s the same idea that drove Lorem Ipsum for type setting placeholders.

Re: What is the history of the use of "foo" and "bar" in source code examples? (2012)

#144
post #35

Earlier quoted context omitted.

When I started to learn programming (by myself), I had a really hard time understanding what foo and bar were and what they meant in various tutorials and blogs. I was already trying to learn the syntax and programming concepts, throwing some unknowns words in the mix did NOT help. For some time I thought foo had special meaning in PHP, or that it meant something in English (not my first language, and I was much less…

If they used 'thing' and 'stuff' would you be happier? A B C? What would you suggest as a generic variable name? > Using foo bar baz qux is lazy when you can easily find countless examples. Countless examples of what?

> If they used 'thing' and 'stuff' would you be happier? A B C?

Yes to both.

> Countless examples of what?

Anything illustrative. Like libraries/books, cars, whatever. Anything is better than foo/bar

Re: What is the history of the use of "foo" and "bar" in source code examples? (2012)

#145

I have always felt that the foo/bar demo/example snippets have held me back in comprehending code, because there was no reasonable logic to it. It just means nothing to me, other than the FUBAR reference others have mentioned. I personally, and professionally, think it’s a horrible convention.

It's supposed to mean nothing; that's the point. You use "foo" and "bar" (and "baz" and "qux", etc) when the names of the things in your example do not matter. It's the same way you'd see examples featuring "x", "y", and "z" when learning algebra: maybe your textbook also has story problems, but most of the examples will simply show an equation in terms of x, y, and maybe z, without pretending that those abstractions…

I think meaningless abstractions are fine to a point, but when you have a less trivial example, it can make it harder to keep track of the relationship of different things. For example, you might see something like

  trait Foo {
      fn frobulate()
  }
  
  struct Bar;
  struct Baz;
  
  impl Foo for Bar {
      fn frobulate() {
          // TODO   
      }
  }

  fn qux(...)
It's ends up being too abstract. A more concrete example would help clarify the relationship of the different elements.

Re: What is the history of the use of "foo" and "bar" in source code examples? (2012)

#146
post #15

Earlier quoted context omitted.

> They have absolutely no connection to the matter at hand. Since foo is often used before bar, you would think there is an ordering between the two but there doesn't have to be. They are hard to pronounce and easier to confuse. I couldn’t disagree more. The entire point is that the variables are disconnected from the matter at hand. They’re widely recognised as placeholders, single syllable, distinctly pronounced fr…

> distinctly pronounced from each other This isn't so much of an advantage for "bar" and "baz". Those sound pretty distinct to Americans, now, but "r" -> "z" is a known type of sound change, which implies that for some people they'll sound the same. "R" -> "s" is attested in Latin, presumably because "z" wasn't an option. (Latin fricatives don't have voicing distinctions.) For an only slightly different current examp…

Show me a phrase and I'll show you a language it doesn't work in.

Re: What is the history of the use of "foo" and "bar" in source code examples? (2012)

#147

Earlier quoted context omitted.

> distinctly pronounced from each other This isn't so much of an advantage for "bar" and "baz". Those sound pretty distinct to Americans, now, but "r" -> "z" is a known type of sound change, which implies that for some people they'll sound the same. "R" -> "s" is attested in Latin, presumably because "z" wasn't an option. (Latin fricatives don't have voicing distinctions.) For an only slightly different current examp…

Show me a phrase and I'll show you a language it doesn't work in.

Is there a language that identifies "ta" and "pa"?

Re: What is the history of the use of "foo" and "bar" in source code examples? (2012)

#149

MIT AI Lab back in the 1960s published technical reports containing program code. The military slang 'FUBAR' f'ed up beyond all recognition, was in the student and professor engineering vocabulary. The tradition became to use 'fu' and 'bar' as nominal function names, in same manner as X and Y were nominal variables. Often in the MIT technical reports, one would see 'x = fu(y)' or 'y > bar(z)' and so forth. If you kne…

On a related note, we all know the story from WW2 where Bastogne was surrounded by the Wehrmacht, and the Wehrmacht sent a note to General McAuliffe suggesting he surrender. He returned with a note that simply said "nuts". I simply did not believe than an American GI ever said "nuts". So, I asked my dad (WW2 veteran). He said he briefly worked for the General, and asked him what he actually wrote. The General laughed…

Maybe the communication went like this:

Germans: "Wie Sie vermutlich wissen, sind Sie und Ihre Leute von allen Seiten umstellt. Wir gehen davon aus, dass Sie bereit sind, sich zu ergeben. Bitte bestätigen Sie dies."

MCAuliffe: "Dies Nutz"

Re: What is the history of the use of "foo" and "bar" in source code examples? (2012)

#150

It blows me away that "The Jargon File" is not required canon. Well, it can be anachronistic and old-school-nerd-bro coded, but there's some primal stuff in there http://catb.org/jargon/html/

There was this thing called the Jargon File. Then it was taken over by a rogue person who removed some things which didn't fit his personal liking and put in some other things. There was a lot of drama, but the end result was a skewed file that emphasized certain parts of hacker culture over others. It might be good to know that you linked to the version which one person had outsized influence of, and should probably…

Was not aware of this, I've been reading the file since like … a very long time. I did always find the "Portrait of J Random Hacker" pretty lame, but really enjoyed the AI Koans, especially "Moon instructs a student".

--

New version has many more terms in the lexicon, but it's good to see the "canonical" terms although the foreword exhibits its own strong bias. Original is missing some of my favorites from the so-called rogue fork like "bogo sort", "magic smoke", and "big red switch"

--

Link to original

https://www.dourish.com/goodies/jargon.html

Post reply on HN