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

This is a discussion on anyone here hate when foo bar baz is used in example code? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; To me there is nothing worst when programmers use the words foo bar and baz in generic example code. Reason ...

  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,175
    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,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.

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

  8. #8
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    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
    Portugal
    Posts
    7,581
    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.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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,812
    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
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    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
    32,834
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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

Page 1 of 2 12 LastLast
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, 11:20 AM
  2. Explain this C code in english
    By soadlink in forum C Programming
    Replies: 16
    Last Post: 08-31-2006, 01: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

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