thisIsAMemberFunctionName vs this_is_a_member_function_name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • E. Robert Tisdale

    #16
    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. This is purely a matter of style.
    [color=blue]
    > Which one should I prefer?
    >
    > thisIsAMemberFu nctionName
    > vs
    > this_is_a_membe r_function_name[/color]

    this->functionName
    [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?
    >
    > 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 best advice that I can give you is

    Keep a Thesaurus handy.

    Choose short complete [English] words for function names,
    constants, variables and types. Don't *mangle* them.
    Try to avoid words like data, object, routine that have special meaning
    or that are redundant in the context of a C++ program.

    If you are writing scientific or engineering applications
    you can implement long formulas with a single compact expression
    using single character symbols annotated with comments:

    // definition // nomenclature
    // ---------------------------------------------------
    double a = 9.8; // acceleration (meters/second/second)
    double m = 1.0 // mass (kilograms)

    double F = m*a; // force (Newtons)


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

    Comment

    • Ed Avis

      #17
      Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

      debajit1@hotmai l.com (Slash) writes:
      [color=blue]
      >thisIsAMemberF unctionName
      >vs
      >this_is_a_memb er_function_nam e[/color]

      Purely a matter of taste. But Stroustrup seems to prefer the latter
      and I feel that if picking a style to emulate, the designer of the
      language is probably the one to follow. Since the standard library
      uses the second style (eg for_each not forEach) you might as well be
      consitent with it.

      But if you use a different class library, you might want to change
      your style to fit in with that (eg MFC prefixes every class with 'C',
      goodness knows why).

      --
      Ed Avis <ed@membled.com >

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

      Comment

      • John Dill

        #18
        Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

        The style does not matter to me as long as it is consistent, but what
        is annoying to me is whether or not to mix styles within a class that
        is derived from a standard library component. I don't think a
        universal coding style is not necessarily irrelevant as some people
        portray. I don't think there is an absolute best objective style, but
        having a universal coding style, which would include the standard
        libraries and open source would be cool, well, as long as I like it ;)

        Best,
        John

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

        Comment

        • kanze@gabi-soft.fr

          #19
          Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

          Jason Carucci <jcarucci@yahoo .com> wrote in message
          news:<091120032 211566435%jcaru cci@yahoo.com>. ..
          [color=blue]
          > In article <341c1613.03110 90823.39bea7bd@ posting.google. com>, Slash
          > <debajit1@hotma il.com> wrote:[/color]
          [color=blue][color=green]
          > > Is there any "standard" naming convention for member functions?
          > > Which one should I prefer?[/color][/color]
          [color=blue][color=green]
          > > thisIsAMemberFu nctionName
          > > vs
          > > this_is_a_membe r_function_name[/color][/color]
          [color=blue][color=green]
          > > 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.[/color][/color]
          [color=blue][color=green]
          > > Why then is the first convention usually recommended?[/color][/color]
          [color=blue][color=green]
          > > 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][/color]
          [color=blue]
          > 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.[/color]

          And it is slightly easier to read with the underscores. Since code will
          be read a lot more often than it is written, you should use underscores.
          And of course, keyboard macros and word completion mean that there isn't
          really any difference in typing, either.

          In practice, with a little practice, the difference is negligible in
          both case. Not enough really to base a choice on.

          --
          James Kanze GABI Software mailto:kanze@ga bi-soft.fr
          Conseils en informatique orientée objet/ http://www.gabi-soft.fr
          Beratung in objektorientier ter Datenverarbeitu ng
          11 rue de Rambouillet, 78460 Chevreuse, France, +33 (0)1 30 23 45 16

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

          Comment

          • Daniel Spangenberg

            #20
            Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name



            John Dill schrieb:
            [color=blue]
            > The style does not matter to me as long as it is consistent, but what
            > is annoying to me is whether or not to mix styles within a class that
            > is derived from a standard library component. I don't think a
            > universal coding style is not necessarily irrelevant as some people
            > portray. I don't think there is an absolute best objective style, but
            > having a universal coding style, which would include the standard
            > libraries and open source would be cool, well, as long as I like it ;)
            >
            > Best,
            > John[/color]

            A similar naming-convention dilemma exists, if you are going to specialize

            template classes of std componets or if you want to provide a namespace
            swap function, which could by used by std::algorithem s (provided that
            some yet unresolved swap issues **are** solved)

            Greetings from Bremen,

            Daniel




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

            Comment

            • John Dill

              #21
              Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

              > But if you use a different class library, you might want to change[color=blue]
              > your style to fit in with that (eg MFC prefixes every class with 'C',
              > goodness knows why).[/color]

              Well, how else would you know that it is a class? ;) I think it came
              in through the hungarian notation that microsoft has supported so I
              surmise that C=class?

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

              Comment

              • Allan W

                #22
                Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

                jbruno4000@aol. com (jbruno4000) wrote[color=blue]
                > This conversation has truly exausted itself![/color]

                Yes, it was doomed from the start. It isn't quite a troll, but the
                topic is one that's guaranteed to generate more heat than light;
                not unlike a message asking what's the best computer language, or
                why we don't all boycott Microsoft.

                For the record: in my opinion, there are some issues where it's much
                more important to have SOME standard, than anything that standard could
                possibly say. When you're working with a group of programmers, you
                should use the same indentation style, the same tab stops (or else only
                use spaces), the same naming conventions, and so on. If your personal
                code stands out in some way (other than comments with your name on it),
                you're making maintenance much more difficult than it needs to be.

                That means doing things even if you think they're stupid. If everyone
                else uses "m_" in front of all member variables, you should do it too
                even if you don't think it clarifies anything. On the other hand, if
                nobody else does it you should refrain as well. If you really think
                that everyone ought to be using "m_" in front of member variables,
                propose it at a team meeting -- be prepared to explain why it's worth
                fixing every line of code already written. (Or bring it up at the
                beginning of the next project, before any code is written.)

                The one exception to this philosophy is comments. AFAIK, nobody has ever
                received negative feedback on their code because the comments were too
                clear. My personal rule of thumb is to put a comment on almost EVERY
                line of code, explaining why it's there (and assuming that all readers
                already understand WHAT it does, so there's no point explaining it:
                totProc += 17; // Add 17 to totProc
                That comment does nothing useful, but
                totProc += 17; // Update running count of orders processed
                does, though you should now explain why 17 is the right value.)

                Comment

                • kanze@gabi-soft.fr

                  #23
                  Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

                  Daniel Spangenberg <dsp@bdal.de> wrote in message
                  news:<3FB2051D. 25D6C66F@bdal.d e>...[color=blue]
                  > John Dill schrieb:[/color]
                  [color=blue][color=green]
                  > > The style does not matter to me as long as it is consistent, but
                  > > what is annoying to me is whether or not to mix styles within a
                  > > class that is derived from a standard library component. I don't
                  > > think a universal coding style is not necessarily irrelevant as some
                  > > people portray. I don't think there is an absolute best objective
                  > > style, but having a universal coding style, which would include the
                  > > standard libraries and open source would be cool, well, as long as I
                  > > like it ;)[/color][/color]
                  [color=blue]
                  > A similar naming-convention dilemma exists, if you are going to
                  > specialize template classes of std componets or if you want to provide
                  > a namespace swap function, which could by used by std::algorithem s
                  > (provided that some yet unresolved swap issues **are** solved)[/color]

                  Yes and no. swap, vector, string and map fit in with both schemes. And
                  who uses anything else:-).

                  Seriously, I sort of like having the library use a different convention.
                  That way, the reader knows to look in the standard, and not in my code,
                  for the documentation. Of course, the leading std:: should be a
                  sufficient give away.

                  In practice, the projects I've worked on have all used the second
                  convention for the project names, and having the standard library names
                  use a different convention doesn't seem to have ever bothered anyone.

                  --
                  James Kanze GABI Software mailto:kanze@ga bi-soft.fr
                  Conseils en informatique orientée objet/ http://www.gabi-soft.fr
                  Beratung in objektorientier ter Datenverarbeitu ng
                  11 rue de Rambouillet, 78460 Chevreuse, France, +33 (0)1 30 23 45 16

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

                  Comment

                  • Gavin Deane

                    #24
                    Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

                    john-dill@uiowa.edu (John Dill) wrote in message news:<302c79f4. 0311120710.3c9a d9ea@posting.go ogle.com>...[color=blue][color=green]
                    > > But if you use a different class library, you might want to change
                    > > your style to fit in with that (eg MFC prefixes every class with 'C',
                    > > goodness knows why).[/color]
                    >
                    > Well, how else would you know that it is a class? ;) I think it came
                    > in through the hungarian notation that microsoft has supported so I
                    > surmise that C=class?[/color]

                    <reposting as similar previous message seems to have got lost>

                    I thought it was a name conflict thing. If I am using the MFC library
                    I can use names like Bitmap, Button, View in my code if I want to
                    because the library only uses names like CBitmap, CButton, CView. I
                    believe Borland does a similar thing with its GUI development library,
                    starting all the class names with 'T', and wxWindows uses 'wx'.
                    Namespaces would be better, but I don't know whether namespaces were
                    available when these libraries started life.

                    This all falls down if you decide that starting class names with 'C'
                    is a really good idea because that's what Microsoft does.

                    GJD

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

                    Comment

                    • Rolf Magnus

                      #25
                      Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

                      Gavin Deane wrote:
                      [color=blue]
                      > john-dill@uiowa.edu (John Dill) wrote in message
                      > news:<302c79f4. 0311120710.3c9a d9ea@posting.go ogle.com>...[color=green][color=darkred]
                      >> > But if you use a different class library, you might want to change
                      >> > your style to fit in with that (eg MFC prefixes every class with
                      >> > 'C', goodness knows why).[/color]
                      >>
                      >> Well, how else would you know that it is a class? ;) I think it came
                      >> in through the hungarian notation that microsoft has supported so I
                      >> surmise that C=class?[/color]
                      >
                      > <reposting as similar previous message seems to have got lost>
                      >
                      > I thought it was a name conflict thing. If I am using the MFC library
                      > I can use names like Bitmap, Button, View in my code if I want to
                      > because the library only uses names like CBitmap, CButton, CView.
                      > I believe Borland does a similar thing with its GUI development
                      > library, starting all the class names with 'T', and wxWindows uses
                      > 'wx'.
                      > Namespaces would be better, but I don't know whether namespaces were
                      > available when these libraries started life.[/color]

                      That may be the reason why they are not used. But what does the C in
                      Microsoft's classes stand for?
                      [color=blue]
                      > This all falls down if you decide that starting class names with 'C'
                      > is a really good idea because that's what Microsoft does.[/color]

                      I thought that Microsoft recommends to do that.



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

                      Comment

                      • Allan W

                        #26
                        Re: thisIsAMemberFu nctionName vs this_is_a_membe r_function_name

                        Rolf Magnus <ramagnus@t-online.de> wrote[color=blue]
                        > But what does the C in
                        > Microsoft's classes stand for?[/color]

                        "Class", afaict.
                        [color=blue][color=green]
                        > > This all falls down if you decide that starting class names with 'C'
                        > > is a really good idea because that's what Microsoft does.[/color]
                        >
                        > I thought that Microsoft recommends to do that.[/color]

                        They do. That doesn't mean it's good advice.
                        (Name clashes and all that.)

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

                        Comment

                        Working...