Hacker News new | ask | show | jobs
by Max_Ehrlich 665 days ago
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 give an example I use variable names that actually make sense and are related to the example. I'm glad that I have been fortunate to not see "foo" and "bar" anywhere in all of the code I've seen in recent memory.

5 comments

> 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 from each other, and have an implied ordering.

> 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 example, the second consonants in "virile" and "vision" are perceived as distinct in American English, but identical in Mandarin Chinese, which is why the sound is spelled as "r" in Hanyu Pinyin and as "j" in Wade-Giles.

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"?
I would agree with the comment you're responding to, too often in tutorials or especially in off hand comments here, I find their usage to assume some common but unindicated convention or subtext and obscure the concept they're trying to convey.
They’re the programmer equivalent of ‘x’ and ‘y’ in mathematics — which programmers don’t use as generic variables because they’re used for “math” embedded in code such as coordinates or measurements.
It’s the same idea that drove Lorem Ipsum for type setting placeholders.
> they are hard to pronounce

I’d find it hard to think of two words easier to pronounce— what do you mean by this?

Proof that for any little thing that existed, exists, or could ever exist in this universe, there will be a non-zero list of human beings unhappy with it. Until the end of humanity, at least...
I am unhappy with your characterisation of my natural human trait of having a preponderance for unhappiness with all possible outcomes.
Proof that the statement is an axiom. And the fact that it's an axiom also falls under the axiomatic principle of guaranteed human unhappiness.
It's like business schools using "widget" for the product and "Acme" for the company — they are dealing in concepts, not absolutes
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 proficient in English at ~14 than I am today).

Using foo bar baz qux is lazy when you can easily find countless examples.

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

The very reason you say something like foo is to avoid using any specific example that might actually mean something and confuse the listener into thinking it matters and focussing on some irrelevant detail instead of the actual concept being illustrated.

You detest that someone says "thing" instead of "house" or something?

"...so you take a thing-"

"what thing?"

"It doesn't matter. It might be anything. So you-"

"A car?"

Come on man.