What do you think of this C++ naming convention?

This is a discussion on What do you think of this C++ naming convention? within the C++ Programming forums, part of the General Programming Boards category; I'm getting started on my first large project, and I'm thinking of using the following convention: Classes, structs, enums, functions, ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    4

    What do you think of this C++ naming convention?

    I'm getting started on my first large project, and I'm thinking of using the following convention:

    Classes, structs, enums, functions, and routines are in MixedUpperAndLowerCase.

    Variables and object declarations are in camelCase.

    Constants are ALL_UPPER_CASE.

    I want to reduce the need for underscores and prefix letters as much as possible. Given C++'s various scopes, I think this convention could work well. What do you think? Any pitfalls?

    Thanks.

  2. #2
    Registered User trainee's Avatar
    Join Date
    Jan 2004
    Posts
    32
    As far as I know that is standard convention, and should work fine.

    trainee

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    126
    Sounds pretty good to me dude. But in my opinion, you should really use whatever naming convention is most logical to you and not what other people tell you is the best. It's mostly a matter of personal preference (unless your employer requires you to use a specific convention, then you'll probably want to use theirs), as long as it's not too far out there. Pretty much everyone names constants and macros in all caps, for example. You want to try to use a convention that is easily understandable by someone reading the code. A lot of people like to use Hungarian notation or other prefixes to indicate the type of the variable, but I don't care for that convention. Whatever convention makes the most sense to you personally is what I would go with. Plus, the convention you named there is pretty standard.

  4. #4
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    I know people will bash me for this,but I actually love the Direct X/Microsoft naming convention of all datatypes/classes/etc. being in caps. Either that, or I type entirely lowercase, sort of like the socket.h file in linux...socket()...connect...accept...

  5. #5
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Looks good, but some people prefer to use ALL_CAPS for preprocessor macros.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  6. #6
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Use whatever your professor or employer requires. Otherwise, you can do whatever floats your boat. Just pick something, and stick to it.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  7. #7
    Registered User
    Join Date
    Jan 2004
    Posts
    4
    Okay, thanks everybody.

  8. #8
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,699
    Most important convention is consistency.

    gg

  9. #9
    Disturbed Boy gustavosserra's Avatar
    Join Date
    Apr 2003
    Posts
    244
    I think that, for large functions for example, one could use characters in front of variables names, for example:
    for parameter use p, example: pClassId or pMatrix
    for class attribute, cl
    for variables created in the function, f
    for global variables gl
    and so on...

    Altought the p, for parameter, could get messy with the p of pointer. But it is just an ideia, use pr instead...

    What do you think abou using also these prefixes for large functions?
    Nothing more to tell about me...
    Happy day =)

  10. #10
    Registered User
    Join Date
    Jan 2004
    Posts
    4
    Originally posted by gustavosserra
    I think that, for large functions for example, one could use characters in front of variables names, for example:
    for parameter use p, example: pClassId or pMatrix
    for class attribute, cl
    for variables created in the function, f
    for global variables gl
    and so on...

    Altought the p, for parameter, could get messy with the p of pointer. But it is just an ideia, use pr instead...

    What do you think abou using also these prefixes for large functions?
    It's an interesting idea, g. I have qualifiers which I append to variables (such as Ptr, Avg, Ttl, Count, and so on). My hope is to not have to use prefixes, and instead use scope and late variable declaration to guide the reader. Though I will probably have to either use gl or namespaces for global variables.

  11. #11
    Disturbed Boy gustavosserra's Avatar
    Join Date
    Apr 2003
    Posts
    244
    Yes cnsr, I agree with you. However, in my programs at least, I have functions that have variables that I do not know how to call, once that there are already others with similar semantic.
    Thanks for your opinion.
    Nothing more to tell about me...
    Happy day =)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. naming conventions?
    By Tox|k in forum C Programming
    Replies: 44
    Last Post: 05-26-2008, 09:29 AM
  2. standard naming conventions?
    By h_howee in forum C++ Programming
    Replies: 8
    Last Post: 11-10-2007, 11:53 PM
  3. Convention in C/C++
    By g4j31a5 in forum C++ Programming
    Replies: 16
    Last Post: 09-03-2006, 10:56 PM
  4. Naming variables, functions...
    By Ariod in forum Tech Board
    Replies: 9
    Last Post: 08-19-2003, 01:17 PM
  5. Replies: 2
    Last Post: 01-04-2003, 01:16 AM

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