Thread: What are good naming conventions?

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    What are good naming conventions?

    Usually the best coding convention is consistency with surrounding code.

    But when you're writing something from scratch, what are some good naming conventions?

    For instance:

    • How do you format your variables? E.g. under_score_names, or CamelCase
    • Do you use prefixes for structs, pointers or typdefs? E.g. mytype_t, or pMyPointer
    • What kind of prefixing do you use to group functions together?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by marek.
    How do you format your variables? E.g. under_score_names, or CamelCase
    The former, but camel case is good too. As you noted, this is about picking a convention and then being consistent.

    Quote Originally Posted by marek.
    Do you use prefixes for structs, pointers or typdefs? E.g. mytype_t, or pMyPointer
    Generally, no.

    Quote Originally Posted by marek.
    What kind of prefixing do you use to group functions together?
    The library name, or an abbreviation thereof.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Are you just fishing for a flame war? There's strong preferences by some that get heated to the point of something akin to a religious war. Not one argument has more merit than the other, but everyone's got their oh-so-important preference. A quick google search will reveal just how absurd these discussions can get.

    The truth is, it doesn't matter what convention you use as long as you're consistent throughout the program. Just be careful to avoid reserved names and prefixes, and try to use meaningful names.
    If you understand what you're doing, you're not learning anything.

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Quote Originally Posted by itsme86 View Post
    The truth is, it doesn't matter what convention you use as long as you're consistent throughout the program. Just be careful to avoid reserved names and prefixes, and try to use meaningful names.
    +2

    See attachment
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In a game Engine...
    By Shamino in forum Game Programming
    Replies: 28
    Last Post: 02-19-2006, 11:30 AM
  2. Good books for learning WIN32 API
    By Junior89 in forum Windows Programming
    Replies: 6
    Last Post: 01-05-2006, 05:38 PM
  3. Good resources for maths and electronics
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 12-22-2004, 04:23 PM
  4. what is good for gaphics in dos
    By datainjector in forum Game Programming
    Replies: 2
    Last Post: 07-15-2002, 03:48 PM
  5. i need links to good windows tuts...
    By Jackmar in forum Windows Programming
    Replies: 3
    Last Post: 05-18-2002, 11:16 PM