C Board  

Go Back   C Board > Community Boards > General Discussions

Reply
 
LinkBack Thread Tools Display Modes
Old 09-25-2006, 04:36 PM   #1
Registered User
 
Join Date: Aug 2005
Posts: 37
anyone here hate when foo bar baz is used in example code?

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?
shintaro is offline   Reply With Quote
Old 09-25-2006, 04:40 PM   #2
Gawking at stupidity
 
Join Date: Jul 2004
Posts: 2,324
Quote:
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
__________________
If you understand what you're doing, you're not learning anything.

Ignore any "advice" esbo tries to give you. It's wrong.
itsme86 is offline   Reply With Quote
Old 09-25-2006, 04:46 PM   #3
Registered User
 
Join Date: Aug 2005
Posts: 37
Quote:
Originally Posted by itsme86
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:

Code:
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?
shintaro is offline   Reply With Quote
Old 09-25-2006, 04:50 PM   #4
Registered User
 
Join Date: Oct 2004
Posts: 151
http://www.catb.org/jargon/html/M/me...-variable.html

Bar bar is just the author being stupid and making a lame pun on "Babar".
__________________
System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

Useful resources:
comp.lang.c FAQ | C++ FQA Lite
zx-1 is offline   Reply With Quote
Old 09-25-2006, 05:15 PM   #5
Registered User
 
jlou's Avatar
 
Join Date: Jul 2003
Posts: 1,088
Quote:
Originally Posted by shintaro
Code:
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.
jlou is offline   Reply With Quote
Old 09-25-2006, 05:40 PM   #6
Gawking at stupidity
 
Join Date: Jul 2004
Posts: 2,324
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.
__________________
If you understand what you're doing, you're not learning anything.

Ignore any "advice" esbo tries to give you. It's wrong.
itsme86 is offline   Reply With Quote
Old 09-25-2006, 05:49 PM   #7
Registered User
 
Join Date: Aug 2005
Posts: 37
Which of these is more readable?

this:
Code:
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:
Code:
Void foo(char baz[100])
{
            strcat (baz, “ quz”);
}
 
void bar(void)
{
            char            baz[100];
           
            sprintf(baz, “qok”);
            foo(baz);
            printf(“%s”, baz);
}

Last edited by shintaro; 09-25-2006 at 05:54 PM.
shintaro is offline   Reply With Quote
Old 09-25-2006, 06:07 PM   #8
Gawking at stupidity
 
Join Date: Jul 2004
Posts: 2,324
They're both wrong.
__________________
If you understand what you're doing, you're not learning anything.

Ignore any "advice" esbo tries to give you. It's wrong.
itsme86 is offline   Reply With Quote
Old 09-25-2006, 06:07 PM   #9
(?<!re)tired
 
Mario F.'s Avatar
 
Join Date: May 2006
Location: Portugal
Posts: 5,661
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.
__________________
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.


Mario F. is online now   Reply With Quote
Old 09-25-2006, 09:28 PM   #10
Registered User
 
Join Date: Aug 2006
Posts: 159
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.
System_159 is offline   Reply With Quote
Old 09-25-2006, 09:52 PM   #11
Sweet
 
Join Date: Aug 2002
Location: Tucson, Arizona
Posts: 1,698
I prefer to name my example classes and such poop and pee.
__________________
Woop?
prog-bman is offline   Reply With Quote
Old 09-25-2006, 11:00 PM   #12
Gas pump powered
 
Yoshi's Avatar
 
Join Date: Oct 2001
Posts: 853
I like egg and spam...
__________________
Yoshi
Yoshi is offline   Reply With Quote
Old 09-25-2006, 11:46 PM   #13
Super Moderator
 
Bubba's Avatar
 
Join Date: Aug 2001
Posts: 7,817
I like green eggs and ham.
Bubba is offline   Reply With Quote
Old 09-25-2006, 11:54 PM   #14
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,706
> 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.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 09-26-2006, 01:20 AM   #15
Reverse Engineer
 
maxorator's Avatar
 
Join Date: Aug 2005
Location: Estonia
Posts: 2,260
Quote:
Originally Posted by shintaro
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"?
__________________
The duck is irrelevant to my point.
maxorator is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Values changing without reason? subtled C Programming 2 04-19-2007 10:20 AM
Explain this C code in english soadlink C Programming 16 08-31-2006 12:48 AM
beach bar (sims type game) DrKillPatient Game Programming 1 03-06-2006 01:32 PM
Who will map the scan code (inserted by VKD_Force_keys) to virtual key code? Unregistered Windows Programming 0 02-21-2002 06:05 PM
Can you have nested code block? What does the compiler do? For example ... albertr C Programming 4 01-16-2002 12:04 AM


All times are GMT -6. The time now is 12:34 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22