Thread: naming conventions?

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    most CBoard members will prefer what I suggested as coding style
    That's very presumptous of you to say considering that personal coding style is a religious issue. Personally, I do not do all that you have commanded.
    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

  2. #17
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by laserlight View Post
    That's very presumptous of you to say considering that personal coding style is a religious issue. Personally, I do not do all that you have commanded.
    Should we create a poll to find out the most popular style?

    If you do not happen to use such style, then what is your style?
    Matters the least, if you do not want to disclose

  3. #18
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > Should we create a poll to find out the most popular style?
    No.

    Or should I say, nO or n_o or whatever else.

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Should we create a poll to find out the most popular style?
    No. Refer to the existing coding style polls to find out why such a poll is useless.

    If you do not happen to use such style, then what is your style?
    Since you are so curious, the naming convention is that part of my personal coding style can be summarised as:
    functionName
    TypeName
    NamedConstant
    variable_name
    MACRO_NAME

    Although names beginning with an underscore followed by a non-uppercase letter are only reserved to the implementation for use in the global and std namespace, I still suggest that an underscore suffix be used instead of a prefix if one wishes to decorate member variable names with an underscore. I consider this more generally consistent.
    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

  5. #20
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by laserlight View Post
    No. Refer to the existing coding style polls to find out why such a poll is useless.
    Well ... leave it then.

    Since you are so curious, the naming convention is that part of my personal coding style can be summarised as:
    functionName
    TypeName
    NamedConstant
    variable_name
    MACRO_NAME
    That is pretty strange and inconsistent style. Do you find difficulty differentiating between variables and functions? And why you do not use the standard practice among all the languages of using all caps for constants?

  6. #21
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > That is pretty strange and inconsistent style.
    It's only inconsistant if you don't stick to it. How can a set of guidelines be inconsistant!?

    > And why you do not use the standard practice among all the languages of using all caps for constants?
    Since when is that standard!?

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You know, differentiating styles for different types (functions, variables, constants), makes it easier to identify what type of something you are referring to.
    I tend more usually to use a few styles and identifiers:

    FunctionName (or sometimes function_name to match those functions available in STL - begin, end, resize, capacity, etc).
    TypeName_t
    NAMED_CONSTANT
    VariableName OR variable_name (typically with a prefix for type such as "p" for pointer, "r" for reference, "str" for string, etc).
    MACRO_NAME
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by zacs7 View Post
    > That is pretty strange and inconsistent style.
    It's only inconsistant if you don't stick to it. How can a set of guidelines be inconsistant!?

    > And why you do not use the standard practice among all the languages of using all caps for constants?
    Since when is that standard!?
    Just to be a little more explicit:
    - Inconsistent within itself. Function names and variable names look different for not reasons known to me. I had asked him. Let him reply first.
    - Inconsistent compared to standard conventions, consts are not all caps.
    - No difference in eg. a class name and a named constant naming.

  9. #24
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > Inconsistent compared to standard conventions
    No such thing.

    > Function names and variable names look different for not reasons known to me.
    And they should be. How do you know what a function is and what a variable is otherwise?

  10. #25
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by zacs7 View Post
    > Inconsistent compared to standard conventions
    No such thing.
    Pointless.

    > Function names and variable names look different for not reasons known to me.
    And they should be. How do you know what a function is and what a variable is otherwise?
    Insanely pointless.
    I wonder you write it like this then,
    Code:
    void FUNCTION_computeSalary() {}
    double VARIABLE_balance;

  11. #26
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by manav View Post
    Insanely pointless.
    I wonder you write it like this then,
    Code:
    void FUNCTION_computeSalary() {}
    double VARIABLE_balance;
    Oh really? I'd say it's quite necessary.
    Looking over some old source, I found a variable and thought "where the heck did this come from?" because it didn't seem to be defined within the scope of the function. Do I really have to be that confused? Of course not.
    That's why it's good to make differentiation between different things. Like prefix member variables with m_ and global variables with g_ and separate variables and functions.

    Is this another of your "it's arrogant" belief?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #27
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by Elysia View Post
    Oh really? I'd say it's quite necessary.
    Looking over some old source, I found a variable and thought "where the heck did this come from?" because it didn't seem to be defined within the scope of the function. Do I really have to be that confused? Of course not.
    That's why it's good to make differentiation between different things. Like prefix member variables with m_ and global variables with g_ and separate variables and functions.
    Defense's argument is mis leading for the court
    Elysia what you said is right. But do you use different name styles, just so that, not to confuse between variables and functions? Highly unbelievable!

    Is this another of your "it's arrogant" belief?
    Not at all. I only find First letter capitalized type names arrogant, except when used for class names etc.

  13. #28
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by manav View Post
    But do you use different name styles, just so that, not to confuse between variables and functions? Highly unbelievable!
    I don't find it unbelievable. The reason I don't do it is because I don't really feel the need to do so. That doesn't mean others do. And my general style is just "MyFunction" and "MyVariable" - ie, the same. But I have been known to lower case both functions and variables at times. I just don't really have any other naming style to apply to functions.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #29
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by Elysia View Post
    I don't find it unbelievable. The reason I don't do it is because I don't really feel the need to do so. That doesn't mean others do. And my general style is just "MyFunction" and "MyVariable" - ie, the same. But I have been known to lower case both functions and variables at times. I just don't really have any other naming style to apply to functions.
    Well zacs and laser are out of it already. Not to stretch any further myself. And Elysia has good points also.

    I would just sum up, saying, I find it rather pointless to worry too much, about naming schemes. For me, a better naming scheme is, in which, identifier names are closer to their real worlds names.

    eg:
    humansCount / humans_count is easier to read
    than
    nHumansCount or m_nHumansCount etc.

  15. #30
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Do you find difficulty differentiating between variables and functions?
    Generally, I do not have difficulty differentiating between syntactic elements after viewing them in context, regardless of the naming convention. If you cannot do that... it would be tough to be a programmer, or even a reader of novels.

    Inconsistent within itself. Function names and variable names look different for not reasons known to me.
    Recall that C++ has function pointers. Aside from that, I find that it helps me mentally remember the functions and variables. As a secondary reason, it increases the number of possible names in the given scope.

    Inconsistent compared to standard conventions, consts are not all caps.
    Macro names do not obey the rules of scope. Consequently, Stroustrup, Meyers, Sutter and Alexandrescu all recommend reserving fully capitalised names for macros.

    No difference in eg. a class name and a named constant naming.
    I do not see a problem since named constants are usually within namespace or class scope.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Forcing code conventions
    By audinue in forum Tech Board
    Replies: 28
    Last Post: 03-31-2009, 08:46 AM
  2. standard naming conventions?
    By h_howee in forum C++ Programming
    Replies: 8
    Last Post: 11-10-2007, 11:53 PM
  3. Naming variables, functions...
    By Ariod in forum Tech Board
    Replies: 9
    Last Post: 08-19-2003, 12:17 PM
  4. C++ conventions
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 03-14-2002, 08:15 AM
  5. C++ and Program Version Naming
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 11-27-2001, 11:19 AM