PDA

View Full Version : anyone here hate when foo bar baz is used in example code?



shintaro
09-25-2006, 04:36 PM
To me there is nothing worst when programmers use the words foo bar and baz in generic example code. Reason being that its so undescriptive, I mean how do you document foo? You should know just by looking at names whether its a variable, fuction name, string output. But how are you supposed to remember what foo does?

itsme86
09-25-2006, 04:40 PM
You should know just by looking at names whether its a variable, fuction name, string output. But how are you supposed to remember what foo does?
Use this cheat sheet:

foo = variable
foo(<args>) = function
"foo" = string

shintaro
09-25-2006, 04:46 PM
Use this cheat sheet:

foo = variable
foo(<args>) = function
"foo" = string

Im really not that stupid.

Try this example, I was currently reading this in the article "Understanding Initialization Lists in C++" which is on this site:


int main()
{
// a lovely elephant ;)
Bar bar;
}
WTF is Bar bar? Can you tell me what kind of statement this is without refering to the article?

zx-1
09-25-2006, 04:50 PM
http://www.catb.org/jargon/html/M/metasyntactic-variable.html

Bar bar is just the author being stupid and making a lame pun on "Babar".

jlou
09-25-2006, 05:15 PM
int main()
{
// a lovely elephant ;)
Bar bar;
}
WTF is Bar bar? Can you tell me what kind of statement this is without refering to the article?Bar is a class and bar is an instance of the class.

itsme86
09-25-2006, 05:40 PM
Or a struct and an instance of a struct ;)

Either way. It's obviously a declaration in the normal form <type> <name>;

and changing Bar to something else still wouldn't tell you if it was a class or a struct.

shintaro
09-25-2006, 05:49 PM
Which of these is more readable?

this:

Void modifyName(char name[100])
{
strcat (name, “ is stupid”);
}

void setUpName(void)
{
char name[100];

sprintf(name, “Jake”);
modifyName(name);
printf(“%s”, name);
}

or this:

Void foo(char baz[100])
{
strcat (baz, “ quz”);
}

void bar(void)
{
char baz[100];

sprintf(baz, “qok”);
foo(baz);
printf(“%s”, baz);
}

itsme86
09-25-2006, 06:07 PM
They're both wrong.

Mario F.
09-25-2006, 06:07 PM
Some people exaggerate their use.

foo, bar and baz should be used as placeholders. Nothing more. Their only purpose is to exemplify or demonstrate some concept. Not to be used as actual names.

For instance, if I'm talking about the relation between two classes, I may want to exemplify with a code where each class is named foo and bar. The name of the classes is meaningless for the argument at hand. foo and bar served only as placeholder names to give meaning to the code.

System_159
09-25-2006, 09:28 PM
what bothers me the most is that it should actually be fu and bar, not foo and bar. Seeing as how fubar stands for F***ed Up Beyond All Repair.

prog-bman
09-25-2006, 09:52 PM
I prefer to name my example classes and such poop and pee.

Yoshi
09-25-2006, 11:00 PM
I like egg and spam...

VirtualAce
09-25-2006, 11:46 PM
I like green eggs and ham.

Salem
09-25-2006, 11:54 PM
> But how are you supposed to remember what foo does?
Because they're never supposed to be used in real code, only examples of concept or syntax.
When you understand that, simply replace them with whatever is actually meaningful in your code.

Side effect - it stops people from simply copy/pasting the answers and actually doing a bit of work.

maxorator
09-26-2006, 01:20 AM
To me there is nothing worst when programmers use the words foo bar and baz in generic example code. Reason being that its so undescriptive, I mean how do you document foo? You should know just by looking at names whether its a variable, fuction name, string output. But how are you supposed to remember what foo does?
Would you prefer words "egg", "ham" and "apple"?

shintaro
09-26-2006, 01:59 AM
Would you prefer words "egg", "ham" and "apple"?
Yes I would. Infact just about any word in the dictionary would work better than foo, bar and baz because most words have a meaning that will describe the purpose the word is being used to represent. The words egg, ham and apple are nouns, they describe a single item, like something that would be stored in a array. Words that are verbs should be used as fuction names. Descriptive names document your code. When creating names for code that will teach a programming concept, it should be all the more important to use descriptive/self documenting names, but people choose to use meaningless words that sound like klingon babble. There are rare occasions when you want to explain a programming concept without directly dealing with how that concept is implemented, and in those rare cases you would use non-descriptive words to isolate the code from how it would be applied. But as Mario F mentioned, the use of foo, bar, baz has been exagerated to the point where it is always used for every code example.

risby
09-26-2006, 04:19 AM
To me there is nothing worst when programmers use the words foo bar and baz in generic example code.
I do not like foo, bar and baz
I just can't cope with all that jazz

I do not like them in my code
I won't be going down that road

They won't appear in my program
Not even for green eggs and ham

I hate to see them in your script
It sucks and makes me really pipped

I've never liked foo, bar and baz
And don't know anyone who has

Driver
09-26-2006, 06:03 AM
It's pretty much all been said, but this Wikipedia entry (http://en.wikipedia.org/wiki/Metasyntactic_variable) explains metasyntactic variables.

Like any system of mnemonics, they can be very useful if used correctly or pig awful if abused / used incorrectly / overused.

indigo0086
09-26-2006, 07:07 AM
*hears the word meta and goes into shell shock*