thisIsAMemberFunctionName vs this_is_a_member_function_name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Slash

    thisIsAMemberFunctionName vs this_is_a_member_function_name

    Is there any "standard" naming convention for member functions?
    Which one should I prefer?

    thisIsAMemberFu nctionName
    vs
    this_is_a_membe r_function_name


    Although most books and eminent authors (like Herb Sutter) recommend
    the first approach, I certainly feel the second leads to more readable
    names. In fact the STL itself uses the second naming convention.

    Why then is the first convention usually recommended?

    I understand that all this is strictly a matter of personal taste, but
    since most of you guys here are pros, what do you all prefer?

    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.m oderated. First time posters: Do this! ]
  • jbruno4000

    #2
    Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

    I think it's important we all follow the same namming convention which is to
    capitalize the first letter of each new word in the name as opposed to an
    underscore. It's also important the function name suggests the action it
    performs.i.e.

    GetPrimeNumbers ();
    SortList();

    JB



    Comment

    • Jack Klein

      #3
      Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

      On 10 Nov 2003 01:47:10 GMT, jbruno4000@aol. com (jbruno4000) wrote in
      comp.lang.c++:
      [color=blue]
      > I think it's important we all follow the same namming convention which is to
      > capitalize the first letter of each new word in the name as opposed to an
      > underscore. It's also important the function name suggests the action it
      > performs.i.e.
      >
      > GetPrimeNumbers ();
      > SortList();
      >
      > JB[/color]

      Yes, but why do you feel that it is important not to have underscores?

      --
      Jack Klein
      Home: http://JK-Technology.Com
      FAQs for
      comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
      comp.lang.c++ http://www.parashift.com/c++-faq-lite/
      alt.comp.lang.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

      Comment

      • Erik Max Francis

        #4
        Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

        Slash wrote:
        [color=blue]
        > Is there any "standard" naming convention for member functions?
        > Which one should I prefer?
        >
        > thisIsAMemberFu nctionName
        > vs
        > this_is_a_membe r_function_name[/color]

        It is purely a stylistic issue, although the Standard Library prefers
        the latter form.

        Like almost all stylistic issues, it is far better to be consistent with
        the other code on your team rather than to doing something uniquely
        clever.

        --
        Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
        __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
        / \ Too much agreement kills a chat.
        \__/ Eldridge Cleaver

        [ See http://www.gotw.ca/resources/clcm.htm for info about ]
        [ comp.lang.c++.m oderated. First time posters: Do this! ]

        Comment

        • lilburne

          #5
          Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

          Slash wrote:[color=blue]
          > Is there any "standard" naming convention for member functions?
          > Which one should I prefer?
          >
          > thisIsAMemberFu nctionName
          > vs
          > this_is_a_membe r_function_name
          >
          >
          > Although most books and eminent authors (like Herb Sutter) recommend
          > the first approach, I certainly feel the second leads to more readable
          > names. In fact the STL itself uses the second naming convention.
          >
          > Why then is the first convention usually recommended?
          >
          > I understand that all this is strictly a matter of personal taste, but
          > since most of you guys here are pros, what do you all prefer?
          >[/color]

          The second version for function names, the first for class
          names. Why because it is our house style. Otherwise it
          doesn't matter. What does matter is that you stick to one
          style or at the very least one style per class.


          [ See http://www.gotw.ca/resources/clcm.htm for info about ]
          [ comp.lang.c++.m oderated. First time posters: Do this! ]

          Comment

          • Stephan Br?nnimann

            #6
            Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

            debajit1@hotmai l.com (Slash) wrote in message news:<341c1613. 0311090823.39be a7bd@posting.go ogle.com>...[color=blue]
            > Is there any "standard" naming convention for member functions?
            > Which one should I prefer?
            >
            > thisIsAMemberFu nctionName
            > vs
            > this_is_a_membe r_function_name
            >
            >
            > Although most books and eminent authors (like Herb Sutter) recommend
            > the first approach, I certainly feel the second leads to more readable
            > names. In fact the STL itself uses the second naming convention.
            >
            > Why then is the first convention usually recommended?
            >
            > I understand that all this is strictly a matter of personal taste, but
            > since most of you guys here are pros, what do you all prefer?[/color]

            I prefer the first format. It doesn't really matter however, you'll get used
            to it very quickly:
            to make sure the whole team uses the same style is much more important.

            Stephan

            [ See http://www.gotw.ca/resources/clcm.htm for info about ]
            [ comp.lang.c++.m oderated. First time posters: Do this! ]

            Comment

            • Tahir Hashmi

              #7
              Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

              debajit1@hotmai l.com (Slash) wrote in message news:<341c1613. 0311090823.39be a7bd@posting.go ogle.com>...[color=blue]
              > Is there any "standard" naming convention for member functions?
              > Which one should I prefer?
              >
              > thisIsAMemberFu nctionName
              > vs
              > this_is_a_membe r_function_name[/color]

              Here's a coding convention that I follow:

              * Capitalize class names LikeThis
              * Use camel notation for methods sayLikeThis()
              * Use all lowercase for variables like_this

              Though the last style is most readable, the names quickly get too
              long. So I prefer using that for the variables. Also, since most
              method invocations are preceeded by a -> or ., the method names stand
              out despite the starting character being in lower case. As for class
              names - the capitalization has just stuck on :)

              --
              Tahir Hashmi (VSE, NCST)
              codemartial.org is your first and best source for all of the information you’re looking for. From general topics to more of what you would expect to find here, codemartial.org has it all. We hope you find what you are searching for!

              tahir AT ncst.ernet.in

              [ See http://www.gotw.ca/resources/clcm.htm for info about ]
              [ comp.lang.c++.m oderated. First time posters: Do this! ]

              Comment

              • Rolf Magnus

                #8
                Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

                Slash wrote:
                [color=blue]
                > Is there any "standard" naming convention for member functions?[/color]

                No.
                [color=blue]
                > Which one should I prefer
                >
                > thisIsAMemberFu nctionName
                > vs
                > this_is_a_membe r_function_name[/color]

                It depends. If your program is mainly based on a library or you are
                writing additions to existing programs, use the one they used. If
                you're doing something on your own, do what you prefer.
                I think the first is used more often, and most often, I'm using it too.
                [color=blue]
                > Although most books and eminent authors (like Herb Sutter) recommend
                > the first approach, I certainly feel the second leads to more readable
                > names. In fact the STL itself uses the second naming convention.
                >
                > Why then is the first convention usually recommended?[/color]

                I don't know why it is recommended, but I don't consider one to be more
                or less readable than the other. This might depend on the font of your
                text editor though.
                [color=blue]
                > I understand that all this is strictly a matter of personal taste, but
                > since most of you guys here are pros, what do you all prefer?[/color]

                I'm not sure that I'd already count as a pro, but one thing that you can
                easily see in your example is that the names get a bit shorter using
                the first method.


                [ See http://www.gotw.ca/resources/clcm.htm for info about ]
                [ comp.lang.c++.m oderated. First time posters: Do this! ]

                Comment

                • Jason Carucci

                  #9
                  Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

                  I prefer the first because typing an underscore takes a little more
                  time. The underscore is a little off to the right and requires you to
                  move your hands to get to the key. If you just use letters, you can
                  type much faster.

                  In article <341c1613.03110 90823.39bea7bd@ posting.google. com>, Slash
                  <debajit1@hotma il.com> wrote:
                  [color=blue]
                  > Is there any "standard" naming convention for member functions?
                  > Which one should I prefer?
                  >
                  > thisIsAMemberFu nctionName
                  > vs
                  > this_is_a_membe r_function_name
                  >
                  >
                  > Although most books and eminent authors (like Herb Sutter) recommend
                  > the first approach, I certainly feel the second leads to more readable
                  > names. In fact the STL itself uses the second naming convention.
                  >
                  > Why then is the first convention usually recommended?
                  >
                  > I understand that all this is strictly a matter of personal taste, but
                  > since most of you guys here are pros, what do you all prefer?[/color]

                  [ See http://www.gotw.ca/resources/clcm.htm for info about ]
                  [ comp.lang.c++.m oderated. First time posters: Do this! ]

                  Comment

                  • Rolf Magnus

                    #10
                    Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

                    jbruno4000 wrote:
                    [color=blue]
                    > I think it's important we all follow the same namming convention which
                    > is to capitalize the first letter of each new word in the name
                    > as opposed to an underscore.[/color]

                    And for what reason do you think that?
                    [color=blue]
                    > It's also important the function name suggests the action it
                    > performs.i.e.[/color]

                    Of course. Although calling them something like f1() to f2341() might be
                    fun if you love obfuscating your code :-)
                    [color=blue]
                    > GetPrimeNumbers ();
                    > SortList();
                    >
                    > JB[/color]

                    Comment

                    • Jack Klein

                      #11
                      Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

                      On 9 Nov 2003 17:54:10 -0500, debajit1@hotmai l.com (Slash) wrote in
                      comp.lang.c++:
                      [color=blue]
                      > Is there any "standard" naming convention for member functions?
                      > Which one should I prefer?
                      >
                      > thisIsAMemberFu nctionName
                      > vs
                      > this_is_a_membe r_function_name
                      >
                      >
                      > Although most books and eminent authors (like Herb Sutter) recommend
                      > the first approach, I certainly feel the second leads to more readable
                      > names. In fact the STL itself uses the second naming convention.
                      >
                      > Why then is the first convention usually recommended?
                      >
                      > I understand that all this is strictly a matter of personal taste, but
                      > since most of you guys here are pros, what do you all prefer?[/color]

                      My personal preference is to have the underscores, whether or not you
                      capitalize the individual words or "wordlets".

                      I have notices that many C and C++ programmers do not seem to mind
                      underscores in variable names, but for some reason don't think they
                      should appear in function names.

                      My theory for their preference rests on two thoughts:

                      1. A long time ago, unique characters in identifier names were very
                      limited, to as little as 6 characters and a single case in early C
                      implementations .

                      2. The Windows API, which was written to be called by name from
                      languages like BASIC and Pascal and others that do not permit
                      underscores in identifier names, so defines all functions in
                      CamelCaseMode.

                      Interestingly enough, none of the programmers who allow underscores in
                      variable, enumeration, type, and macro identifiers but don't like them
                      in function names agree with my reasoning, even though some of them
                      have extensive Windows programming experience. But none of them has
                      ever proposed an alternate theory, either.

                      I have heard of studies alleging to prove that underscores improve
                      recognition greatly, but don't have any links handy.

                      --
                      Jack Klein
                      Home: http://JK-Technology.Com
                      FAQs for
                      comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
                      comp.lang.c++ http://www.parashift.com/c++-faq-lite/
                      alt.comp.lang.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

                      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
                      [ comp.lang.c++.m oderated. First time posters: Do this! ]

                      Comment

                      • Nicola Musatti

                        #12
                        Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

                        debajit1@hotmai l.com (Slash) wrote in message news:<341c1613. 0311090823.39be a7bd@posting.go ogle.com>...[color=blue]
                        > Is there any "standard" naming convention for member functions?
                        > Which one should I prefer?
                        >
                        > thisIsAMemberFu nctionName
                        > vs
                        > this_is_a_membe r_function_name[/color]

                        In a sense a standard exists, in that the standard library uses the
                        second convention you describe. Apart from that, however, everyone has
                        his/her own favourite style, to the point that endless debates take
                        place periodically in this and other newsgroups. As I don't feel like
                        participating in such a debate today, I'll stick to "agnostic" advice:
                        Be consistent in your own code and try to agree to a project wide
                        standard. Which one doesn't matter much (unless you're working on a
                        project with me, in which case MY favourite style is the only possible
                        choice :-)

                        Cheers,
                        nicolaMusatti ;-)

                        [ See http://www.gotw.ca/resources/clcm.htm for info about ]
                        [ comp.lang.c++.m oderated. First time posters: Do this! ]

                        Comment

                        • jbruno4000

                          #13
                          Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

                          I just like the idea of everybody following the same naming convention. It all
                          comes down to personal preference.

                          Comment

                          • Rolf Magnus

                            #14
                            Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

                            jbruno4000 wrote:
                            [color=blue]
                            > I just like the idea of everybody following the same naming
                            > convention.[/color]

                            That might be a nice thing, but why do you think that it's so important
                            that it's the one you use? Just because you're too lazy to change? ;-)

                            Comment

                            • jbruno4000

                              #15
                              Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

                              This conversation has truly exausted itself!

                              Comment

                              Working...