Thread: anyone here hate when foo bar baz is used in example code?

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    44

    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?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    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.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    44
    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?

  4. #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

  5. #5
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    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.

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    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.

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    44
    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.

  8. #8
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    They're both wrong.
    If you understand what you're doing, you're not learning anything.

  9. #9
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    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.

  10. #10
    Registered User
    Join Date
    Aug 2006
    Posts
    163
    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.

  11. #11
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    I prefer to name my example classes and such poop and pee.
    Woop?

  12. #12
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859
    I like egg and spam...
    Yoshi

  13. #13
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I like green eggs and ham.

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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.
    If at first you don't succeed, try writing your phone number on the exam paper.

  15. #15
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    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 Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  2. Explain this C code in english
    By soadlink in forum C Programming
    Replies: 16
    Last Post: 08-31-2006, 12:48 AM
  3. beach bar (sims type game)
    By DrKillPatient in forum Game Programming
    Replies: 1
    Last Post: 03-06-2006, 01:32 PM
  4. Replies: 0
    Last Post: 02-21-2002, 06:05 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM