matching { } syntax style

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

    matching { } syntax style

    Why is it that everybody likes the follwowing curly braces syntax

    function() {
    implementations ;
    }

    I find the following much better to read (C style)

    function()
    {
    implementations ;
    }

    kind regards,
    Bart


  • Phlip

    #2
    Re: matching { } syntax style

    > Why is it that everybody likes the follwowing curly braces syntax[color=blue]
    >
    > function() {
    > implementations ;
    > }[/color]

    They don't. Some like it and some don't.
    [color=blue]
    > I find the following much better to read (C style)
    >
    > function()
    > {
    > implementations ;
    > }[/color]

    For style, I follow the ultimate acknowledge reference for English - /The
    Elements of Style/.

    It says to use parallel construction on parallel concepts.

    Don't say, "The big red lion lay down with the lamb, small and furry".

    Say, "The big red lion lay down with the small furry lamb."

    The adjectives parallel their relation to their noun.

    So, in programming, put the curly braces where they parallel each other.

    --
    Phlip


    Comment

    • jeffc

      #3
      Re: matching { } syntax style


      "bart" <bart@thatissec ret.nlm> wrote in message
      news:3f86b7e8$0 $58711$e4fe514c @news.xs4all.nl ...[color=blue]
      > Why is it that everybody likes the follwowing curly braces syntax
      >
      > function() {
      > implementations ;
      > }
      >
      > I find the following much better to read (C style)
      >
      > function()
      > {
      > implementations ;
      > }[/color]

      I don't think everybody does like the former. I think at least half the
      people prefer the latter.


      Comment

      • Ron Natalie

        #4
        Re: matching { } syntax style


        "bart" <bart@thatissec ret.nlm> wrote in message news:3f86b7e8$0 $58711$e4fe514c @news.xs4all.nl ...[color=blue]
        > Why is it that everybody likes the follwowing curly braces syntax
        >
        > function() {
        > implementations ;
        > }
        >
        > I find the following much better to read (C style)
        >
        > function()
        > {
        > implementations ;
        > }
        >[/color]
        What makes you think the latter is C style? And what makes you think it's
        easier to read?


        Comment

        • Tim Clacy

          #5
          Re: matching { } syntax style

          bart wrote:[color=blue]
          > Why is it that everybody likes the follwowing curly braces syntax
          >
          > function() {
          > implementations ;
          > }
          >
          > I find the following much better to read (C style)
          >
          > function()
          > {
          > implementations ;
          > }
          >
          > kind regards,
          > Bart[/color]

          Some of us don't like either; they're there to make compiler writers lives
          easier, not ours.


          Comment

          • Stewart Gordon

            #6
            Re: matching { } syntax style

            While it was 10/10/03 2:50 pm throughout the UK, bart sprinkled little
            black dots on a white screen, and they fell thus:[color=blue]
            > Why is it that everybody likes the follwowing curly braces syntax
            >
            > function() {
            > implementations ;
            > }[/color]

            I'm one of everybody, amn't I? I personally hate it when people can't
            be bothered to indent.
            [color=blue]
            > I find the following much better to read (C style)
            >
            > function()
            > {
            > implementations ;
            > }[/color]

            Well, I guess that

            function() {
            implementations ;
            }

            gives the best of both worlds. :-)

            Stewart.

            --
            My e-mail is valid but not my primary mailbox. Please keep replies on
            on the 'group where everyone may benefit.

            Comment

            • Thomas Matthews

              #7
              Re: matching { } syntax style

              bart wrote:
              [color=blue]
              > Why is it that everybody likes the follwowing curly braces syntax
              >
              > function() {
              > implementations ;
              > }
              >
              > I find the following much better to read (C style)
              >
              > function()
              > {
              > implementations ;
              > }
              >
              > kind regards,
              > Bart
              >
              >[/color]

              Some people like this style:
              return_type
              function()
              {
              implementation;
              }
              The braces show the indentation.

              I prefer to have the braces line up to help show the indentation
              levels.

              But this is what they call a religious issue; there is no
              correct answer, only what people believe.

              --
              Thomas Matthews

              C++ newsgroup welcome message:

              C++ Faq: http://www.parashift.com/c++-faq-lite
              C Faq: http://www.eskimo.com/~scs/c-faq/top.html
              alt.comp.lang.l earn.c-c++ faq:

              Other sites:
              http://www.josuttis.com -- C++ STL Library book

              Comment

              • Patrick Kowalzick

                #8
                Re: matching { } syntax style

                Hi bart,
                [color=blue]
                > function() {
                > implementations ;
                > }[/color]

                This style has a very big advantage when you use a single-line debugger, In
                fact not for a function. Try an if instead.

                When you use these two cases with a single-line debugger...

                if (someboolexpres sion)
                dosomething;

                if (someboolexpres sion) {
                dosomethingmore ;
                }

                ...and the line with an if appears the curly brace tells you that a block is
                following. If not one single command follows.
                [color=blue]
                > function()
                > {
                > implementations ;
                > }[/color]

                I personally like this style more. In my opinion it is more readable. But I
                do not use a single-line debugger. So I assume that I am not part of
                "everybody" .

                Regards,
                Patrick


                Comment

                • Tim Clacy

                  #9
                  Re: matching { } syntax style

                  Tim Clacy wrote:[color=blue]
                  > bart wrote:[color=green]
                  >> Why is it that everybody likes the follwowing curly braces syntax
                  >>
                  >> function() {
                  >> implementations ;
                  >> }
                  >>
                  >> I find the following much better to read (C style)
                  >>
                  >> function()
                  >> {
                  >> implementations ;
                  >> }
                  >>
                  >> kind regards,
                  >> Bart[/color]
                  >
                  > Some of us don't like either; they're there to make compiler writers
                  > lives easier, not ours.[/color]

                  ....and just to set the cat amongst the pigeons, I'm quite fond of this:

                  void fn() {
                  while (...) {
                  switch (...) {
                  case :
                  case :
                  default : } } }

                  :-)


                  Comment

                  • Default User

                    #10
                    Re: matching { } syntax style

                    bart wrote:[color=blue]
                    >
                    > Why is it that everybody likes the follwowing curly braces syntax
                    >
                    > function() {
                    > implementations ;
                    > }
                    >
                    > I find the following much better to read (C style)[/color]

                    If anything, the former is C-style, as it was used by the originators of
                    C in K&R. Often refered to as K&R style or OTBS (one true brace style).
                    [color=blue]
                    >
                    > function()
                    > {
                    > implementations ;
                    > }[/color]


                    I have a preference for Whitesmith's style:

                    if (1)
                    {
                    std::cout << "code!\n";
                    }


                    Just pick a style and use it consistently.



                    Brian Rodenborn

                    Comment

                    • Howard

                      #11
                      Re: matching { } syntax style

                      [color=blue]
                      >... And what makes you think it's easier to read?[/color]

                      Umm...the fact that *he* finds it easier to read, perhaps? (Does an opinion
                      need a reason?) And I agree. For some reason (i have no idea why), I find
                      it much easier to quickly spot braces that are aligned vertically than a
                      closing brace matching the start of a line of text. So, for me, it's easier
                      to read.

                      On the other hand, my boss, who wrote the code I'm updating and maintaining,
                      likes it the other way. Must be why he's the boss. :-)

                      -Howard






                      Comment

                      • Kris Wempa

                        #12
                        Re: matching { } syntax style


                        "bart" <bart@thatissec ret.nlm> wrote in message
                        news:3f86b7e8$0 $58711$e4fe514c @news.xs4all.nl ...[color=blue]
                        > Why is it that everybody likes the follwowing curly braces syntax
                        >
                        > function() {
                        > implementations ;
                        > }
                        >
                        > I find the following much better to read (C style)
                        >
                        > function()
                        > {
                        > implementations ;
                        > }
                        >
                        > kind regards,
                        > Bart
                        >[/color]

                        I prefer your second style in functions only. If statement blocks like I
                        prefer to use the first. I just don't see the point in dedicating an ENTIRE
                        line to a measly '{'. I'd much rather write:

                        if (x == 10) {

                        }

                        than:

                        if (x == 10)
                        {

                        }

                        As long as my closing '}' is lined up DIRECTLY under the statement that
                        opened it, I find it easy to read.



                        Comment

                        • lilburne

                          #13
                          Re: matching { } syntax style

                          bart wrote:
                          [color=blue]
                          > Why is it that everybody likes the follwowing curly braces syntax
                          >
                          > function() {
                          > implementations ;
                          > }
                          >
                          > I find the following much better to read (C style)
                          >
                          > function()
                          > {
                          > implementations ;
                          > }
                          >[/color]

                          Pick a style any style and stick to it. Personally I prefer

                          function()
                          {
                          if (expression) {
                          statements;
                          }
                          }

                          but that is because it is our house style. Prior to my
                          current place I preferred another style, it doesn't matter a
                          jot, which you use. But if you are programming with others a
                          standard style is a great help. I can look over any piece of
                          code in the company and the layout is the same, it looks my
                          code, and my code looks like anyone else's. The standard
                          layout helps you to understand what is happening.
                          Occasionally we receive code from some outside source that
                          does not conform to our standard, and it is always
                          difficult to read. That doesn't mean that it is wrong, or a
                          bad style, its just that it isn't the one we are used to.


                          Comment

                          • J. Campbell

                            #14
                            Re: matching { } syntax style

                            "bart" <bart@thatissec ret.nlm> wrote in message news:<3f86b7e8$ 0$58711$e4fe514 c@news.xs4all.n l>...[color=blue]
                            > Why is it that everybody likes the follwowing curly braces syntax
                            >
                            > function() {
                            > implementations ;
                            > }
                            >
                            > I find the following much better to read (C style)
                            >
                            > function()
                            > {
                            > implementations ;
                            > }
                            >
                            > kind regards,
                            > Bart[/color]

                            Bart...I agree with the others. It's a matter of preference. I'm
                            pretty new to C++, and as I was getting started, I read several essays
                            on styles. I ended up using Bruce Eckel's book's style. eg:

                            function(){
                            implementations ;
                            }

                            I like this style because:
                            1) it takes up less space, vertically.
                            2) you read the function name, immediately see the open bracket, and
                            then look down to where the scope for that indentation ends.

                            My one minor exception to that I sometimes adopt is for if else
                            statements:

                            function(){
                            if(expression){
                            statement1;
                            statement2;
                            }else{
                            statement1;
                            statement2;
                            }
                            }

                            However, I also sometimes do single line if else if it fits nicely
                            onto one line.

                            function(){
                            if(expression) statement; else statement;
                            }

                            Comment

                            • Phlip

                              #15
                              Re: matching { } syntax style

                              Tim Clacy wrote:
                              [color=blue]
                              > ...and just to set the cat amongst the pigeons, I'm quite fond of this:
                              >
                              > void fn() {
                              > while (...) {
                              > switch (...) {
                              > case :
                              > case :
                              > default : } } }
                              >
                              > :-)[/color]

                              I'm fond of very short functions, and replacing switch statements with
                              virtual messages, so my bad-ass pidgeon is not alarmed by your silly
                              little cat.

                              --
                              Phlip

                              Comment

                              Working...