Writing name in C, C++

Discussion in 'Programmer's Corner' started by anhnha, Sep 18, 2014.

  1. anhnha

    Thread Starter Active Member

    Apr 19, 2012
    774
    48
    Here are some definitions of class, struct and union.

    Code (Text):
    1. class CFoo
    2. {
    3.    // CFoo is a CLASS defined by using 'class' keyword
    4. };
    Code (Text):
    1. struct SFoo
    2. {
    3.    // SFoo is a CLASS defined by using 'struct' keyword
    4. };
    Code (Text):
    1. union UFoo
    2. {
    3.    // UFoo is a CLASS defined by using 'union' keyword
    4. };
    As you can see, the name of "CFoo", "SFoo", "UFoo" are started by the letter "C", "S" and "U" respectively.
    I guess they are short for "Class", "Struct" and "Union".
    What is the purpose of writing a name like that? Is it just easy to remember?
     
  2. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,910
    2,173
    It's just a Mnemonic
    You can call them any legal name in the computer language but with a large program some sort of naming convention helps you to remember the types, functions and methods.
    http://en.wikipedia.org/wiki/Naming_convention_(programming)
     
    anhnha likes this.
  3. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    Except for "Ufoo" I think that might be an insult.





    (j/k)
     
    Eric007, anhnha and tshuck like this.
  4. vpoko

    Member

    Jan 5, 2012
    258
    47
    It's called Hungarian notation, it's meant to remind you of the type of a variable. The reason that you're having a hard time figuring out why it's useful is because it isn't, and the practice is more commonly discouraged than encouraged.
     
    anhnha likes this.
  5. anhnha

    Thread Starter Active Member

    Apr 19, 2012
    774
    48
  6. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,910
    2,173
    Some people are pretty anal about code styles in large projects. The Linux kernel is a good example, to have code accepted in the main source tree it doesn't have to follow his coding style but if you don't it's unlikely anyone one will sign-off your patch until you do.

    One of the good things about an IDE like MPLABX/NetBeans is that it will auto-format code to the style of your choice.
     
Loading...