C++ Guidelines

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

    #61
    Re: C++ Guidelines


    "Pete Vidler" <pvidler@mailbl ocks.com> wrote in message
    news:OVZdc.83$7 w.18@newsfe1-gui.server.ntli .net...[color=blue][color=green]
    > >
    > > A suggestion. Functions could easily be longer once you add blank lines[/color][/color]
    and[color=blue][color=green]
    > > comments. Functions that are pretty straightforward but long, say[/color][/color]
    because[color=blue][color=green]
    > > they have to read in a lot of input arguments, are fine, it seems to me.[/color][/color]
    As[color=blue][color=green]
    > > soon as you start to process input arguments and do stuff, that's when[/color][/color]
    the[color=blue][color=green]
    > > 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]

    Worry about cohesion rather than number of lines. If you worry too much
    about number of lines, then you'll start breaking down every 2 lines into
    function, and that can make things *less* readable ultimately.


    Comment

    • Siemel Naran

      #62
      Re: C++ Guidelines

      "jeffc" <nobody@nowhere .com> wrote in message
      news:407ac299_1 @news1.prserv.n et...[color=blue]
      > "Siemel Naran" <SiemelNaran@RE MOVE.att.net> wrote in message[/color]
      [color=blue][color=green][color=darkred]
      > > > - Header files should be self contained, from various sources.[/color]
      > >
      > > What?[/color]
      >
      > Makes sense to me, and I wholeheartedly agree. Nothing worse than
      > unnecessary dependencies in header files.[/color]

      You mean like header A.h fails to include B.h though it depends on entities
      from B.h. Then the user who includes A.h has to include B.h first then A.h.
      Is this what you mean? If so, definitely this is a good rule.

      In fact, my cpp files always include the h file as the first non-comment
      line. But in windows they have this stdafx.h if you use pre-compiled
      headers, and so you shouldn't by accident include B.h in this file.


      Comment

      • Steven T. Hatton

        #63
        Re: C++ Guidelines

        Pete Vidler wrote:
        [color=blue]
        > I am not patting myself on the back. I do not believe it will be obvious
        > to me. It's just that the book has some /very/ mixed reviews on the
        > internet, so I need some solid reassurance that it covers the kind of
        > guidelines that I mentioned earlier before I go out and buy it.
        >
        > -- Pete[/color]
        I got to #3, and so far, I'm finding these worth considering. I suggest
        reading with your eyes open. #3 threw me for a loop at first.

        The Top 20 C++ Tips of All Time

        --
        STH
        Hatton's Law: "There is only One inviolable Law"
        KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
        Mozilla: http://www.mozilla.org

        Comment

        • Steven T. Hatton

          #64
          Re: C++ Guidelines

          Steven T. Hatton wrote:
          [color=blue]
          > Pete Vidler wrote:
          >[color=green]
          >> I am not patting myself on the back. I do not believe it will be obvious
          >> to me. It's just that the book has some /very/ mixed reviews on the
          >> internet, so I need some solid reassurance that it covers the kind of
          >> guidelines that I mentioned earlier before I go out and buy it.
          >>
          >> -- Pete[/color]
          > I got to #3, and so far, I'm finding these worth considering. I suggest
          > reading with your eyes open. #3 threw me for a loop at first.[/color]

          Doh! #2 is the one that tripped me up.
          [color=blue]
          > The Top 20 C++ Tips of All Time
          > http://www.devx.com/cplus/Article/16328/0/page/1[/color]

          Can I trust #4? I believe I can by virtue of this:

          3.6.2 Initialization of non-local objects [basic.start.ini t]

          1 The storage for objects with static storage duration
          (_basic.stc.sta tic_) shall be zero-initialized (_dcl.init_) before any
          other initialization takes place. Objects of POD types
          (_basic.types_) with static storage duration initialized with constant
          expressions (_expr.const_) shall be initialized before any dynamic
          initialization takes place. Objects of namespace scope with static
          storage duration defined in the same translation unit and dynamically
          initialized shall be initialized in the order in which their defini-
          tion appears in the translation unit. [Note: _dcl.init.aggr_
          describes the order in which aggregate members are initialized. The
          initialization of local static objects is described in _stmt.dcl_. ]

          But I'm not sure if there are any subtelties I need to be aware of.
          --
          STH
          Hatton's Law: "There is only One inviolable Law"
          KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
          Mozilla: http://www.mozilla.org

          Comment

          • Christopher Benson-Manica

            #65
            Re: C++ Guidelines

            Siemel Naran <SiemelNaran@re move.att.net> spoke thus:
            [color=blue]
            > In fact, my cpp files always include the h file as the first non-comment
            > line. But in windows they have this stdafx.h if you use pre-compiled
            > headers, and so you shouldn't by accident include B.h in this file.[/color]

            If one writes header files correctly, including header files
            accidently causes very minor effects at worst.

            --
            Christopher Benson-Manica | I *should* know what I'm talking about - if I
            ataru(at)cybers pace.org | don't, I need to know. Flames welcome.

            Comment

            Working...