C++ Guidelines

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

    #16
    Re: C++ Guidelines

    Pete Vidler <pvidler@mailbl ocks.com> wrote:
    [color=blue]
    > Daniel T. wrote:
    > [snip][color=green]
    > > Check out these two books:
    > > "Large-Scale C++ Software Design" by John Lakos[/color]
    >
    > I've heard of this one, but isn't it seriously out of date? I've also
    > heard that he has some strange guidelines like not using namespaces?
    >[color=green]
    > > "Object-Oriented Design Heuristics" by Arthur J. Riel[/color]
    >
    > I'll look into it, thanks.
    >[color=green]
    > > This site may also be helpful:
    > > <http://www.chris-lott.org/resources/cstyle/>[/color]
    >
    > Most of the links there appear to be documents detailing naming
    > conventions and recommending a given style for the placement of braces.
    > I'm looking for more along the lines of design guidelines like I posted
    > (there was one good page there though, thanks).
    >
    > I don't really need the basic stuff (I know most of them), but I am
    > looking for more advanced guidelines (with justifications, like the one
    > about making virtual methods private).[/color]

    Try the articles at this site:
    <http://tinyurl.com/2tt4h >

    Comment

    • Daniel T.

      #17
      Re: C++ Guidelines

      Pete Vidler <pvidler@mailbl ocks.com> wrote:
      [color=blue]
      > Daniel T. wrote:
      > [snip][color=green]
      > > Check out these two books:
      > > "Large-Scale C++ Software Design" by John Lakos[/color]
      >
      > I've heard of this one, but isn't it seriously out of date? I've also
      > heard that he has some strange guidelines like not using namespaces?
      >[color=green]
      > > "Object-Oriented Design Heuristics" by Arthur J. Riel[/color]
      >
      > I'll look into it, thanks.
      >[color=green]
      > > This site may also be helpful:
      > > <http://www.chris-lott.org/resources/cstyle/>[/color]
      >
      > Most of the links there appear to be documents detailing naming
      > conventions and recommending a given style for the placement of braces.
      > I'm looking for more along the lines of design guidelines like I posted
      > (there was one good page there though, thanks).
      >
      > I don't really need the basic stuff (I know most of them), but I am
      > looking for more advanced guidelines (with justifications, like the one
      > about making virtual methods private).[/color]

      Try the articles at this site:
      <http://tinyurl.com/2tt4h >

      Comment

      • Steven T. Hatton

        #18
        Re: C++ Guidelines

        Pete Vidler wrote:
        [color=blue]
        > David Harmon wrote:
        > [snip][color=green]
        >> Well, arguing over the placement of braces has less potential for harm
        >> than many of the design guidelines I have seen.[/color]
        >
        > Yes, but there's no potential for learning anything with
        > brace-placement. You can already see the possibilities.
        >
        > -- Pete[/color]
        This looks like food for thought. I'm not endorsing, just passing it on:


        You may already be aware of this. It's general, but certainly has a link or
        five that will be relevant:

        --
        p->m == (*p).m == p[0].m

        Modernize your infrastructure with SUSE Linux Enterprise servers, cloud technology for IaaS, and SUSE's software-defined...


        Comment

        • Steven T. Hatton

          #19
          Re: C++ Guidelines

          Pete Vidler wrote:
          [color=blue]
          > David Harmon wrote:
          > [snip][color=green]
          >> Well, arguing over the placement of braces has less potential for harm
          >> than many of the design guidelines I have seen.[/color]
          >
          > Yes, but there's no potential for learning anything with
          > brace-placement. You can already see the possibilities.
          >
          > -- Pete[/color]
          This looks like food for thought. I'm not endorsing, just passing it on:


          You may already be aware of this. It's general, but certainly has a link or
          five that will be relevant:

          --
          p->m == (*p).m == p[0].m

          Modernize your infrastructure with SUSE Linux Enterprise servers, cloud technology for IaaS, and SUSE's software-defined...


          Comment

          • Claudio Puviani

            #20
            Re: C++ Guidelines

            "Pete Vidler" <pvidler@mailbl ocks.com> wrote[color=blue]
            > Claudio Puviani wrote:
            > [snip][color=green]
            > >[/color][/color]
            http://search.barnesandnoble.com/boo...sbn=0521893089[color=blue][color=green]
            > >
            > > It's basically an extension of what used to be Rogue
            > > Wave's guidelines. No one will agree with every
            > > guideline, but they're mostly reasonable.[/color]
            >
            > Interesting.. but the summary says it deals with formatting,
            > naming, documentation, etc. I was looking for design
            > guidelines along the lines of those that I posted. Am I
            > correct in assuming it doesn't cover such issues?[/color]

            It has rudimentary design guidelines as well. The formatting section is just
            a few pages, and the least interesting at that.

            Here's a list of books I posted once before that would give you what you
            need:

            For general inheritance guidelines, strategies, pitfalls, etc. (in no
            particular order):

            "C++ Primer" by Lippman and Lajoie
            "Effective C++" by Scott Meyers
            "More Effective C++" by Scott Meyers
            "Effective STL" by Scott Meyers
            "Exceptiona l C++" by Herb Sutter
            "More Exceptional C++" by Herb Sutter
            "Large Scale C++ Software Design" by John Lakos
            "Designing and Coding Reusable C++" by Carroll and Ellis
            "Rumination s on C++" by Koenig and Moo
            "Enough Rope to Shoot Yourself in the Foot" by Allen Holub
            "C++ Strategies and Tactics" by Bob Murray
            "C++ Programming Style" by Tom Cargill
            "C++ in Action" by Bartosz Milewski
            "C++ Code Capsules" by Chuck Allison
            and even the old but excellent "Advanced C++" by James Coplien

            Claudio Puviani


            Comment

            • Claudio Puviani

              #21
              Re: C++ Guidelines

              "Pete Vidler" <pvidler@mailbl ocks.com> wrote[color=blue]
              > Claudio Puviani wrote:
              > [snip][color=green]
              > >[/color][/color]
              http://search.barnesandnoble.com/boo...sbn=0521893089[color=blue][color=green]
              > >
              > > It's basically an extension of what used to be Rogue
              > > Wave's guidelines. No one will agree with every
              > > guideline, but they're mostly reasonable.[/color]
              >
              > Interesting.. but the summary says it deals with formatting,
              > naming, documentation, etc. I was looking for design
              > guidelines along the lines of those that I posted. Am I
              > correct in assuming it doesn't cover such issues?[/color]

              It has rudimentary design guidelines as well. The formatting section is just
              a few pages, and the least interesting at that.

              Here's a list of books I posted once before that would give you what you
              need:

              For general inheritance guidelines, strategies, pitfalls, etc. (in no
              particular order):

              "C++ Primer" by Lippman and Lajoie
              "Effective C++" by Scott Meyers
              "More Effective C++" by Scott Meyers
              "Effective STL" by Scott Meyers
              "Exceptiona l C++" by Herb Sutter
              "More Exceptional C++" by Herb Sutter
              "Large Scale C++ Software Design" by John Lakos
              "Designing and Coding Reusable C++" by Carroll and Ellis
              "Rumination s on C++" by Koenig and Moo
              "Enough Rope to Shoot Yourself in the Foot" by Allen Holub
              "C++ Strategies and Tactics" by Bob Murray
              "C++ Programming Style" by Tom Cargill
              "C++ in Action" by Bartosz Milewski
              "C++ Code Capsules" by Chuck Allison
              and even the old but excellent "Advanced C++" by James Coplien

              Claudio Puviani


              Comment

              • Claudio Puviani

                #22
                Re: C++ Guidelines

                "Pete Vidler" <pvidler@mailbl ocks.com> wrote[color=blue]
                > Daniel T. wrote:
                > [snip][color=green]
                > > Check out these two books:
                > > "Large-Scale C++ Software Design" by John Lakos[/color]
                >
                > I've heard of this one, but isn't it seriously out of date?[/color]

                Good information is never out of date. Knuth's "Art of Computer Programming"
                series was first published in 1968 and anyone would get shot for calling it
                out of date. A discriminating reader can easily filter out what's still
                relevant and what isn't. Those who can't are probably not ready to read the
                book yet.
                [color=blue]
                > I've also heard that he has some strange guidelines like
                > not using namespaces?[/color]

                EVERY book that proposes guidelines has strange guidelines. Or at least, we
                perceive them as being strange because the author comes from a different
                background. The thing to remember is that guidelines are NOT rules and
                should be followed only if they make sense in a given context. Taking John's
                admonition against using namespaces out of context is less than meaningless.
                What he actually suggested, which anyone who actually read the book would
                know, is to wait until namespace support was more stable and universal
                before using it. At the time the book was written, there were quite a few
                compilers that didn't support namespaces or that supported them incorrectly.

                The truth is that whether or not one appreciates John's style or agrees with
                every detail, anyone who hasn't read the book is a step behind those who
                have with regard to physical design.

                Claudio Puviani


                Comment

                • Claudio Puviani

                  #23
                  Re: C++ Guidelines

                  "Pete Vidler" <pvidler@mailbl ocks.com> wrote[color=blue]
                  > Daniel T. wrote:
                  > [snip][color=green]
                  > > Check out these two books:
                  > > "Large-Scale C++ Software Design" by John Lakos[/color]
                  >
                  > I've heard of this one, but isn't it seriously out of date?[/color]

                  Good information is never out of date. Knuth's "Art of Computer Programming"
                  series was first published in 1968 and anyone would get shot for calling it
                  out of date. A discriminating reader can easily filter out what's still
                  relevant and what isn't. Those who can't are probably not ready to read the
                  book yet.
                  [color=blue]
                  > I've also heard that he has some strange guidelines like
                  > not using namespaces?[/color]

                  EVERY book that proposes guidelines has strange guidelines. Or at least, we
                  perceive them as being strange because the author comes from a different
                  background. The thing to remember is that guidelines are NOT rules and
                  should be followed only if they make sense in a given context. Taking John's
                  admonition against using namespaces out of context is less than meaningless.
                  What he actually suggested, which anyone who actually read the book would
                  know, is to wait until namespace support was more stable and universal
                  before using it. At the time the book was written, there were quite a few
                  compilers that didn't support namespaces or that supported them incorrectly.

                  The truth is that whether or not one appreciates John's style or agrees with
                  every detail, anyone who hasn't read the book is a step behind those who
                  have with regard to physical design.

                  Claudio Puviani


                  Comment

                  • Siemel Naran

                    #24
                    Re: C++ Guidelines

                    "Pete Vidler" <pvidler@mailbl ocks.com> wrote in message
                    news:ShTdc.309$ sp4.218@newsfe1-
                    [color=blue]
                    > I'm wondering if there is a compilation of C++ guidelines out there
                    > anywhere. Here are some of the ones I've picked up so far (as examples):[/color]

                    We should have guidelines and suggestions. Suggestions are weaker than
                    guidelines.

                    [color=blue]
                    > - Functions should fit on one screen, from various sources.[/color]

                    A suggestion. Functions could easily be longer once you add blank lines and
                    comments. Functions that are pretty straightforward but long, say because
                    they have to read in a lot of input arguments, are fine, it seems to me. As
                    soon as you start to process input arguments and do stuff, that's when the
                    long function should raise a bell.

                    A related concept is that functions should have few input arguments.

                    [color=blue]
                    > - Non-leaf classes should be abstract (have pure virtual methods), from
                    > More Effective C++, Item 33.[/color]

                    A suggestion. Sometimes we want a reasonable default behavior which clients
                    can then override. Requring the above as a guideline imposes too much
                    design burden on the project and could cause it to run out of budget.

                    [color=blue]
                    > - Virtual methods should be private by default and protected if they
                    > need access to a base classes version (except for the destructor, of
                    > course), from http://www.gotw.ca/publications/mill18.htm.[/color]

                    They should be private or protected. Often, a virtual function will call
                    the same function in the base class and do some additional processing, as
                    for example a virtual equal function. I generally call the private virtual
                    functions myaction, and the protected ones doaction.

                    [color=blue]
                    > - Header files should be self contained, from various sources.[/color]

                    What?

                    [color=blue]
                    > - Destructors for base classes should be either virtual or protected.[/color]

                    No. Classes meant to not be derived from may have public non-virtual
                    destructors, such as std::vector.

                    [color=blue]
                    > I think I've probably missed (or never heard of) quite a few more.
                    > Anyone know where I can find such things? Or have some guidelines of
                    > their own to share?[/color]

                    There are lots of others.


                    Comment

                    • Siemel Naran

                      #25
                      Re: C++ Guidelines

                      "Pete Vidler" <pvidler@mailbl ocks.com> wrote in message
                      news:ShTdc.309$ sp4.218@newsfe1-
                      [color=blue]
                      > I'm wondering if there is a compilation of C++ guidelines out there
                      > anywhere. Here are some of the ones I've picked up so far (as examples):[/color]

                      We should have guidelines and suggestions. Suggestions are weaker than
                      guidelines.

                      [color=blue]
                      > - Functions should fit on one screen, from various sources.[/color]

                      A suggestion. Functions could easily be longer once you add blank lines and
                      comments. Functions that are pretty straightforward but long, say because
                      they have to read in a lot of input arguments, are fine, it seems to me. As
                      soon as you start to process input arguments and do stuff, that's when the
                      long function should raise a bell.

                      A related concept is that functions should have few input arguments.

                      [color=blue]
                      > - Non-leaf classes should be abstract (have pure virtual methods), from
                      > More Effective C++, Item 33.[/color]

                      A suggestion. Sometimes we want a reasonable default behavior which clients
                      can then override. Requring the above as a guideline imposes too much
                      design burden on the project and could cause it to run out of budget.

                      [color=blue]
                      > - Virtual methods should be private by default and protected if they
                      > need access to a base classes version (except for the destructor, of
                      > course), from http://www.gotw.ca/publications/mill18.htm.[/color]

                      They should be private or protected. Often, a virtual function will call
                      the same function in the base class and do some additional processing, as
                      for example a virtual equal function. I generally call the private virtual
                      functions myaction, and the protected ones doaction.

                      [color=blue]
                      > - Header files should be self contained, from various sources.[/color]

                      What?

                      [color=blue]
                      > - Destructors for base classes should be either virtual or protected.[/color]

                      No. Classes meant to not be derived from may have public non-virtual
                      destructors, such as std::vector.

                      [color=blue]
                      > I think I've probably missed (or never heard of) quite a few more.
                      > Anyone know where I can find such things? Or have some guidelines of
                      > their own to share?[/color]

                      There are lots of others.


                      Comment

                      • Pete Vidler

                        #26
                        Re: C++ Guidelines

                        Siemel Naran wrote:
                        [snip][color=blue][color=green]
                        >>I'm wondering if there is a compilation of C++ guidelines out there
                        >>anywhere. Here are some of the ones I've picked up so far (as examples):[/color]
                        >
                        > We should have guidelines and suggestions. Suggestions are weaker than
                        > guidelines.[/color]

                        I see no difference. I am just as free to ignore either. The purpose of
                        my post was to find out what various people (or websites, books, etc)
                        might have to say about what they consider to be "good" design.
                        [color=blue][color=green]
                        >>- Functions should fit on one screen, from various sources.[/color]
                        >
                        > A suggestion. Functions could easily be longer once you add blank lines and
                        > comments. Functions that are pretty straightforward but long, say because
                        > they have to read in a lot of input arguments, are fine, it seems to me. As
                        > soon as you start to process input arguments and do stuff, that's when the
                        > long function should raise a bell.
                        >
                        > A related concept is that functions should have few input arguments.[/color]

                        I usually adhere to this one because I find that I make fewer mistakes
                        if the entire method is immediately available. I'm not sure how this
                        relates to the number of arguments, but I'll accept that as a suggestion.
                        [color=blue][color=green]
                        >>- Non-leaf classes should be abstract (have pure virtual methods), from
                        >>More Effective C++, Item 33.[/color]
                        >
                        > A suggestion. Sometimes we want a reasonable default behavior which clients
                        > can then override. Requring the above as a guideline imposes too much
                        > design burden on the project and could cause it to run out of budget.[/color]

                        You can have pure virtual methods with an implementation. Note that
                        abstract in this case means simply that the class has >=1 pure virtual
                        method, not that they are all pure virtual (my interpretation of that
                        source).

                        Having tried this in a recent project, it really isn't that much of a
                        burden (most of my classes were close anyway).
                        [color=blue][color=green]
                        >>- Virtual methods should be private by default and protected if they
                        >>need access to a base classes version (except for the destructor, of
                        >>course), from http://www.gotw.ca/publications/mill18.htm.[/color]
                        >
                        > They should be private or protected. Often, a virtual function will call
                        > the same function in the base class and do some additional processing, as
                        > for example a virtual equal function. I generally call the private virtual
                        > functions myaction, and the protected ones doaction.[/color]

                        Aside from the naming that is exactly what I posted? Except that I'm not
                        too sure about having a virtual "equal function".
                        [color=blue][color=green]
                        >>- Header files should be self contained, from various sources.[/color]
                        >
                        > What?[/color]

                        I posted more info on this elsewhere in the thread. Basically I just
                        meant that you should be able to include the header at the very top of
                        your source file and not get errors.
                        [color=blue][color=green]
                        >>- Destructors for base classes should be either virtual or protected.[/color]
                        >
                        > No. Classes meant to not be derived from may have public non-virtual
                        > destructors, such as std::vector.[/color]

                        Umm.. since when is std::vector a base class? A base class is one that
                        has been (or is intended to be) derived from (IMO).

                        [snip][color=blue]
                        > There are lots of others.[/color]

                        That doesn't help. The entire purpose of my post was to get people to
                        post some (or post links, etc).

                        -- Pete

                        Comment

                        • Pete Vidler

                          #27
                          Re: C++ Guidelines

                          Siemel Naran wrote:
                          [snip][color=blue][color=green]
                          >>I'm wondering if there is a compilation of C++ guidelines out there
                          >>anywhere. Here are some of the ones I've picked up so far (as examples):[/color]
                          >
                          > We should have guidelines and suggestions. Suggestions are weaker than
                          > guidelines.[/color]

                          I see no difference. I am just as free to ignore either. The purpose of
                          my post was to find out what various people (or websites, books, etc)
                          might have to say about what they consider to be "good" design.
                          [color=blue][color=green]
                          >>- Functions should fit on one screen, from various sources.[/color]
                          >
                          > A suggestion. Functions could easily be longer once you add blank lines and
                          > comments. Functions that are pretty straightforward but long, say because
                          > they have to read in a lot of input arguments, are fine, it seems to me. As
                          > soon as you start to process input arguments and do stuff, that's when the
                          > long function should raise a bell.
                          >
                          > A related concept is that functions should have few input arguments.[/color]

                          I usually adhere to this one because I find that I make fewer mistakes
                          if the entire method is immediately available. I'm not sure how this
                          relates to the number of arguments, but I'll accept that as a suggestion.
                          [color=blue][color=green]
                          >>- Non-leaf classes should be abstract (have pure virtual methods), from
                          >>More Effective C++, Item 33.[/color]
                          >
                          > A suggestion. Sometimes we want a reasonable default behavior which clients
                          > can then override. Requring the above as a guideline imposes too much
                          > design burden on the project and could cause it to run out of budget.[/color]

                          You can have pure virtual methods with an implementation. Note that
                          abstract in this case means simply that the class has >=1 pure virtual
                          method, not that they are all pure virtual (my interpretation of that
                          source).

                          Having tried this in a recent project, it really isn't that much of a
                          burden (most of my classes were close anyway).
                          [color=blue][color=green]
                          >>- Virtual methods should be private by default and protected if they
                          >>need access to a base classes version (except for the destructor, of
                          >>course), from http://www.gotw.ca/publications/mill18.htm.[/color]
                          >
                          > They should be private or protected. Often, a virtual function will call
                          > the same function in the base class and do some additional processing, as
                          > for example a virtual equal function. I generally call the private virtual
                          > functions myaction, and the protected ones doaction.[/color]

                          Aside from the naming that is exactly what I posted? Except that I'm not
                          too sure about having a virtual "equal function".
                          [color=blue][color=green]
                          >>- Header files should be self contained, from various sources.[/color]
                          >
                          > What?[/color]

                          I posted more info on this elsewhere in the thread. Basically I just
                          meant that you should be able to include the header at the very top of
                          your source file and not get errors.
                          [color=blue][color=green]
                          >>- Destructors for base classes should be either virtual or protected.[/color]
                          >
                          > No. Classes meant to not be derived from may have public non-virtual
                          > destructors, such as std::vector.[/color]

                          Umm.. since when is std::vector a base class? A base class is one that
                          has been (or is intended to be) derived from (IMO).

                          [snip][color=blue]
                          > There are lots of others.[/color]

                          That doesn't help. The entire purpose of my post was to get people to
                          post some (or post links, etc).

                          -- Pete

                          Comment

                          • Pete Vidler

                            #28
                            Re: C++ Guidelines

                            Claudio Puviani wrote:
                            [snip][color=blue]
                            > It has rudimentary design guidelines as well. The formatting section is just
                            > a few pages, and the least interesting at that.[/color]

                            But how rudimentary? I can't possibly buy a book on the off-chance it
                            might contain what I need (I couldn't afford it). I can't find any
                            actual reviews of the book, and the only info in the summary suggets the
                            book is about formatting/naming conventions (useless to me).
                            [color=blue]
                            > Here's a list of books I posted once before that would give you what you
                            > need:[/color]

                            Cool, thanks. I have read most of these, but there are one or two on
                            that list I haven't seen before.

                            -- Pete

                            Comment

                            • Pete Vidler

                              #29
                              Re: C++ Guidelines

                              Claudio Puviani wrote:
                              [snip][color=blue]
                              > It has rudimentary design guidelines as well. The formatting section is just
                              > a few pages, and the least interesting at that.[/color]

                              But how rudimentary? I can't possibly buy a book on the off-chance it
                              might contain what I need (I couldn't afford it). I can't find any
                              actual reviews of the book, and the only info in the summary suggets the
                              book is about formatting/naming conventions (useless to me).
                              [color=blue]
                              > Here's a list of books I posted once before that would give you what you
                              > need:[/color]

                              Cool, thanks. I have read most of these, but there are one or two on
                              that list I haven't seen before.

                              -- Pete

                              Comment

                              • Pete Vidler

                                #30
                                Re: C++ Guidelines

                                Claudio Puviani wrote:
                                [snip][color=blue][color=green]
                                >>I've heard of this one, but isn't it seriously out of date?[/color]
                                >
                                > Good information is never out of date. Knuth's "Art of Computer Programming"
                                > series was first published in 1968 and anyone would get shot for calling it
                                > out of date. A discriminating reader can easily filter out what's still
                                > relevant and what isn't. Those who can't are probably not ready to read the
                                > book yet.[/color]

                                Right, but if it almost pre-dates namespaces there is going to be a lot
                                missing from it -- am I right? Templates and such?

                                Knuth's book is somewhat different, the concepts it addresses are not
                                based on a language that has changed a great deal over time. It isn't
                                even based on a real language at all (unless you count a few
                                implementations by enthusiasts).
                                [color=blue][color=green]
                                >>I've also heard that he has some strange guidelines like
                                >>not using namespaces?[/color]
                                >
                                > EVERY book that proposes guidelines has strange guidelines. Or at least, we
                                > perceive them as being strange because the author comes from a different
                                > background. The thing to remember is that guidelines are NOT rules and
                                > should be followed only if they make sense in a given context.[/color]
                                [snip]

                                I have to disagree. I have read many guideline type books (the
                                "Effective" and "Exceptiona l" books to name five) that I have had no
                                disagreements with at all. I don't believe I come from the same
                                background as the authors.
                                [color=blue]
                                > The truth is that whether or not one appreciates John's style or agrees with
                                > every detail, anyone who hasn't read the book is a step behind those who
                                > have with regard to physical design.[/color]
                                [snip]

                                That cannot possibly be true. If we haven't read the book we might still
                                know everything it contains (through other sources) and not realise it.
                                And for all I know, if I do read it much of its contents might be
                                obvious to me.

                                -- Pete

                                Comment

                                Working...