Thread: this_is_my_variable_name

  1. #1
    Banned
    Join Date
    Nov 2007
    Posts
    678

    this_is_my_variable_name

    i really like "all lower letters and words separated by underscores" naming convention.
    i don't want to start a flame war. every body knows that it depends on situation and other factors
    which one is used/preferred etc.

    but i really wish to stick to this style. i heard that most Linux coders hate this:
    thisIsMyVariableName
    but they prefer and love this:
    this_is_my_variable_name

    now if i choose the latter (which i really like), will i be hated by say windows coders now?

    i think as far as i am consistent, no one will point a finger at me or force me to change my style!

    can i assume that this is widely adopted style also?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    i think as far as i am consistent, no one will point a finger at me or force me to change my style!
    If you happen to work on source written by someone else, you might be "forced" to temporarily change your style so as to retain consistency.

    can i assume that this is widely adopted style also?
    Yes.
    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
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    That's a bit stereotypical.

    For example, I program at least on Windows and Linux. I use underscores for function names, but camel-style for variable names... Works for me.

  4. #4
    Banned
    Join Date
    Nov 2007
    Posts
    678
    thanks laser and zacs!
    i find that underscore style is most readable (easy on my eyes) and camel style is most beautiful. it has a certain professional look to it.

    as laser pointed, if working on a existing project, you have to follow what has been already decided upon.

    i am also using camel style all through my project.
    i thing this thread will go nowhere, just like my Linux vs Windows thread.

    please do not post any more comments here.
    i wish i could delete this thread (i wanted to, when no body replied, but was unable to do so).

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    I use camel-humps... don't know why... I just like it better and it makes me see things more clearly. Maybe it's because I have a strict spacing convention in my code and the underscores make me feel as though I'm looking at more variables than I am. Of course if you work in a project group, they generally define a naming convention for the whole team whether you prefer it or not... so I'd say get used to dealing with all of the popular styles.
    Sent from my iPadŽ

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    MyPreferenceIsToNameVariablesAndStuffLikeThis
    CClasses CAnd CStuff CGets CPrefixed CLike CThis

    Code:
    class CStuff
    {
      public:
        void DoStuff();
      private:
        int StoreStuff;
    };
    
    struct SStuff
    {
      int StoreStuff;
    };
    
    enum EStuff
    {
      Stuffy,
      Stuffa,
    };
    
    SStuff StuffAndStuff1;
    CStuff* StuffAndStuff2;
    Last edited by Magos; 04-09-2008 at 09:41 AM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by zacs7 View Post
    That's a bit stereotypical.

    For example, I program at least on Windows and Linux. I use underscores for function names, but camel-style for variable names... Works for me.
    Same and same. I use underscores for everything except variables actually.

    I've chewed my way through pretty much every style over the years - not working in teams or anything, I've just changed a lot seeing what I like best. The only thing I can't stand reading and would verbally complain about in a team environment is this:

    Code:
    void some_function(void)
            {
                    // code
            }
    Eww.

    EDIT:

    Or:

    Code:
    void another_function(void)
            {
            // oh my god
            }
    Last edited by cboard_member; 04-09-2008 at 08:01 AM.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  8. #8
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    What about this?
    Code:
    void MY_function(void) { /* A statement; Another statement; More statements; return; */ }
    Sent from my iPadŽ

  9. #9
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Oh my.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  10. #10
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Mine's pretty much like Magos' with a few quirks...

    I start names with lowercase

    Code:
    int thisVar;
    int thatFunction();
    
    // I wish I was consistent in adopting a verb-noun or noun-verb style, but I'm not.
    I use underscores to identify private members;

    Code:
    class CClass { // I also use C to identify my user defined objects... almost always
    public:
       /* ... */
    private:
       int thisValue_;
       int thatFunction_();
    }
    Finally, my constants are all uppercase and I'm yet to be consistent around enumerations (can somebody suggest something I end up liking?).

    As a last note. I break my own styles here and there. For instance, I find that on those rare instances where i have to name something with one of the known types, the underscore works better: std::string format_double(double val, const std::string &format);
    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.

  11. #11
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    In java I use the same style that everything else is coded in except I like to have the opening brace to a block of code sit on its own line. In other languges i have chopped and changed a bit. Generally for variable names I like lowercase + undercores, and for functions I like to capitalise each word. To me that makes functions stand out clearly.

    edit: camel case is ugly :P

  12. #12
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    I like the java conventions. Camel all the way. I don't mind underscores but I detest the hungarian notation.

    m_ptr_CXWTF?QRMyFuntion().... .bleh.

  13. #13
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by mike_g View Post
    In java I use the same style that everything else is coded in except I like to have the opening brace to a block of code sit on its own line.
    Most people seem to like this, however, I've always been more fond of keeping the opening brace on the same line as the definition (or statement, as the case may be) and no indentation on the closing brace.
    Code:
    if (true) {
        /* Code Body */
    }
    
    void myFunction(void) {
       /* Code Body */
    }
    Constants are generally written in full caps with underscores between words (if it is several words, which my constants usally aren't), variables are camel case, function and class definitions are the same way... pointers generally will have "ptr" somewhere in its identifier (the exception being obvious pointers like the *child member of a BST class). I guess that's about it... easy rules to follow and I haven't had any trouble reading my code, nor has anyone else that's read it. I am in work so I don't have any modern C code to show... however, I found an old little snake game I wrote on the internet that should give an idea of my style. Here is a sample (nevermind the poor coding (like not checking the result of malloc)):
    Code:
    void initGame(snakeGame *game) {
        HANDLE hOut;
        CONSOLE_CURSOR_INFO ConCurInf; 
        SMALL_RECT DisplayArea = {30, 0, 72, 23};
        
        /* Initialize the game window */
        hOut = GetStdHandle(STD_OUTPUT_HANDLE);
        ConCurInf.dwSize = 1;
        ConCurInf.bVisible = FALSE;
        SetConsoleCursorInfo(hOut, &ConCurInf);
        SetConsoleWindowInfo(hOut, TRUE, &DisplayArea);
        SetConsoleTitle("Snake");
        
        srand(time(0));  /* rand() is used in generating the apple location */
    Last edited by SlyMaelstrom; 04-09-2008 at 10:41 AM.
    Sent from my iPadŽ

  14. #14
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    I use lowercase letters with underscores for word separation. The primary reason is that it matches the coding style of STL. It is also easier for my eyes to pick out the individual words of the identifier.

  15. #15
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by SlyMaelstrom View Post
    Most people seem to like this, however, I've always been more fond of keeping the opening brace on the same line as the definition (or statement, as the case may be) and no indentation on the closing brace.[CODE]if (/*condition*/) {
    The downside to this is that many automated tools scan for function definitions by looking for a opening curly brace in the first column. So in many projects where the style is, "put the brace on the same line," there is a special exception for function definitions, just to keep these tools happy.

Popular pages Recent additions subscribe to a feed