Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Brace style

Brace style

Scheduled Pinned Locked Moved The Lounge
comquestion
140 Posts 69 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N N a v a n e e t h

    Which one you prefer ?

    if{
    //do something
    }

    Or

    if
    {
    //do something
    }


    printf("Navaneeth!!") www.w3hearts.com

    S Offline
    S Offline
    Stephen Hewitt
    wrote on last edited by
    #6

    The latter; the first form drives me nuts.

    Steve

    1 Reply Last reply
    0
    • N N a v a n e e t h

      Which one you prefer ?

      if{
      //do something
      }

      Or

      if
      {
      //do something
      }


      printf("Navaneeth!!") www.w3hearts.com

      D Offline
      D Offline
      Dario Solera
      wrote on last edited by
      #7

      The real problem with braces is not the style itself, but different styles in the same project, or even file. Most IDEs can reformat the code, but that way there are a few problems with source control... BTW, I prefer this:

      if(true) {
      // Blah
      }

      If you truly believe you need to pick a mobile phone that "says something" about your personality, don't bother. You don't have a personality. A mental illness, maybe - but not a personality. - Charlie Brooker My Blog - My Photos - ScrewTurn Wiki

      K V 2 Replies Last reply
      0
      • N ne0h

        I need this option: IF ' blah blah END IF ;P

        ---------------------------- **** JOB23743 Submitted ****

        B Offline
        B Offline
        benjymous
        wrote on last edited by
        #8

        #define IF(x) if((x)){
        #define ENDIF }
        #define INC(x) x++
        #define DIM int
        #define LET
        #define RND(x) rand()%x

        DIM n;
        LET n=RND(500);
        IF( n<100 )
        INC(n);
        ENDIF

        :laugh:

        1 Reply Last reply
        0
        • N N a v a n e e t h

          Which one you prefer ?

          if{
          //do something
          }

          Or

          if
          {
          //do something
          }


          printf("Navaneeth!!") www.w3hearts.com

          K Offline
          K Offline
          Kyudos
          wrote on last edited by
          #9

          The second form is preferable, I don't know how anyone can put up with the lack of symmetry in the first form. UGH! X| X| X|

          J 1 Reply Last reply
          0
          • S Shog9 0

            The latter. The former is used only by miscreants and rogues. :suss:

            ----

            i hope you are feeling sleepy for people not calling you by the same.

            --BarnaKol on abusive words

            S Offline
            S Offline
            SimonRigby
            wrote on last edited by
            #10

            LOL That used to be me. Don't know why but lately I switched to the latter.

            The only thing unpredictable about me is just how predictable I'm going to be.

            M 1 Reply Last reply
            0
            • N N a v a n e e t h

              Which one you prefer ?

              if{
              //do something
              }

              Or

              if
              {
              //do something
              }


              printf("Navaneeth!!") www.w3hearts.com

              K Offline
              K Offline
              Kent Sharkey
              wrote on last edited by
              #11

              I used to work with a guy that strongly argued for: if { //do something } (He felt that "as a container", the braces themselves needed to be indented. There was a survey back on the old DevelopMentor boards when .NET was still young. The result was about 30% #1, 70% #2 and 1 person "#3")

              -------------- TTFN - Kent

              K 1 Reply Last reply
              0
              • S Shog9 0

                The latter. The former is used only by miscreants and rogues. :suss:

                ----

                i hope you are feeling sleepy for people not calling you by the same.

                --BarnaKol on abusive words

                1 Offline
                1 Offline
                123 0
                wrote on last edited by
                #12

                [Message Deleted]

                L J S J A 5 Replies Last reply
                0
                • N N a v a n e e t h

                  Which one you prefer ?

                  if{
                  //do something
                  }

                  Or

                  if
                  {
                  //do something
                  }


                  printf("Navaneeth!!") www.w3hearts.com

                  M Offline
                  M Offline
                  micmanos
                  wrote on last edited by
                  #13

                  The later ... but when i'm furiously typing, sometimes the Enter doesn't hit and that damn bracket stays on the same line .... When such hidious sine is uppon me i immediatelly grab my whip, face the floor and start whipping my self on the back shouting "FORGIVE MY KEYBOARD FATHER FOR IT DOESN'T KNOW WHAT IT'S DOING" :->

                  1 Reply Last reply
                  0
                  • N N a v a n e e t h

                    Which one you prefer ?

                    if{
                    //do something
                    }

                    Or

                    if
                    {
                    //do something
                    }


                    printf("Navaneeth!!") www.w3hearts.com

                    D Offline
                    D Offline
                    David Wulff
                    wrote on last edited by
                    #14

                    Navaneeth.Which one you prefer ?

                    Over the shoulder with a single clip at the back. I find the ones that attach at each side far too restrictive.


                    Ðavid Wulff What kind of music should programmers listen to?
                    Join the Code Project Last.fm group | dwulff
                    I'm so gangsta I eat cereal without the milk

                    1 Reply Last reply
                    0
                    • N N a v a n e e t h

                      Which one you prefer ?

                      if{
                      //do something
                      }

                      Or

                      if
                      {
                      //do something
                      }


                      printf("Navaneeth!!") www.w3hearts.com

                      F Offline
                      F Offline
                      Frank Kerrigan
                      wrote on last edited by
                      #15

                      Last one complies to coding standards. First one is for folk who don't know any better. How about an if that runs only 1 line of code. A: if{//do something} dothis other code..... B: if{//do something} { dothis } other code.....

                      Grady Booch: I told Google to their face...what you need is some serious adult supervision. (2007 Turing lecture) http://www.frankkerrigan.com/[^]

                      G P 2 Replies Last reply
                      0
                      • S Shog9 0

                        The latter. The former is used only by miscreants and rogues. :suss:

                        ----

                        i hope you are feeling sleepy for people not calling you by the same.

                        --BarnaKol on abusive words

                        J Offline
                        J Offline
                        Jorgen Sigvardsson
                        wrote on last edited by
                        #16

                        Mmm.. yes. You better watch behind your bracket when you code. ;)

                        -- Raaaaaaaaaaaaaaaaaaaaa!

                        1 Reply Last reply
                        0
                        • F Frank Kerrigan

                          Last one complies to coding standards. First one is for folk who don't know any better. How about an if that runs only 1 line of code. A: if{//do something} dothis other code..... B: if{//do something} { dothis } other code.....

                          Grady Booch: I told Google to their face...what you need is some serious adult supervision. (2007 Turing lecture) http://www.frankkerrigan.com/[^]

                          G Offline
                          G Offline
                          Graham J Newton
                          wrote on last edited by
                          #17

                          This is all about readability (compilers don't give two hoots). Braces around one line of code make it LESS readable -- your codes ends up spanning too many lines / pages. Btw, indentation is vital, so the form should be: if (condition) do domething; other code where the blank line before the 'other code' is also vital. (And then there's the debate about whether there should be some comments against each block of code, but I won't go there!)

                          G 1 Reply Last reply
                          0
                          • G Graham J Newton

                            This is all about readability (compilers don't give two hoots). Braces around one line of code make it LESS readable -- your codes ends up spanning too many lines / pages. Btw, indentation is vital, so the form should be: if (condition) do domething; other code where the blank line before the 'other code' is also vital. (And then there's the debate about whether there should be some comments against each block of code, but I won't go there!)

                            G Offline
                            G Offline
                            Graham J Newton
                            wrote on last edited by
                            #18

                            Do'h, of course HTML strips spaces! so, try again:     if (condition)         do something;     other code;

                            F D 2 Replies Last reply
                            0
                            • G Graham J Newton

                              Do'h, of course HTML strips spaces! so, try again:     if (condition)         do something;     other code;

                              F Offline
                              F Offline
                              Frank Kerrigan
                              wrote on last edited by
                              #19

                              :-D

                              Grady Booch: I told Google to their face...what you need is some serious adult supervision. (2007 Turing lecture) http://www.frankkerrigan.com/[^]

                              1 Reply Last reply
                              0
                              • N N a v a n e e t h

                                Which one you prefer ?

                                if{
                                //do something
                                }

                                Or

                                if
                                {
                                //do something
                                }


                                printf("Navaneeth!!") www.w3hearts.com

                                P Offline
                                P Offline
                                Pete OHanlon
                                wrote on last edited by
                                #20

                                Who cares? Does this actually improve the quality of your code in any way? Does the first version produce different code to the second? It doesn't matter. As long as you are consistent and follow internal coding standards then it shouldn't matter which one it is.

                                Deja View - the feeling that you've seen this post before.

                                N K 2 Replies Last reply
                                0
                                • N N a v a n e e t h

                                  Which one you prefer ?

                                  if{
                                  //do something
                                  }

                                  Or

                                  if
                                  {
                                  //do something
                                  }


                                  printf("Navaneeth!!") www.w3hearts.com

                                  M Offline
                                  M Offline
                                  Mark II
                                  wrote on last edited by
                                  #21

                                  if (condition) {     //do something } This is the only true way. All else is heresy. ;P Seriously, I think this all just comes down to personal preference. Everyone has his or her own reasons for preferring one style to another. Those reasons could be to do with practicality, ideology, aesthetics, familiarity, or just following standards. In my case, I like the above layout because it takes up fewer lines on the screen, so I can see more of my code at once. I simply can't see why some people think that the alternatives look nicer. Also, my background is in languages that don't have “curlies”, but whose layout is more like this layout. For example, the structure of VB.Net code is similar: If condtion THEN     'do something END IF Perhaps this similarity to VB.Net is really what some people object to? My Blog: http://www.allwrong.com[^]

                                  K J 2 Replies Last reply
                                  0
                                  • N N a v a n e e t h

                                    Which one you prefer ?

                                    if{
                                    //do something
                                    }

                                    Or

                                    if
                                    {
                                    //do something
                                    }


                                    printf("Navaneeth!!") www.w3hearts.com

                                    J Offline
                                    J Offline
                                    Jaiprakash M Bankolli
                                    wrote on last edited by
                                    #22

                                    I would certainly go with second style as it make readiability more easier

                                    Regards, Jaiprakash M Bankolli jaiprakash.bankolli@gmail.com My Blog Suggestions for me

                                    1 Reply Last reply
                                    0
                                    • N N a v a n e e t h

                                      Which one you prefer ?

                                      if{
                                      //do something
                                      }

                                      Or

                                      if
                                      {
                                      //do something
                                      }


                                      printf("Navaneeth!!") www.w3hearts.com

                                      N Offline
                                      N Offline
                                      Niall Joubert
                                      wrote on last edited by
                                      #23

                                      As long as there are braces, there will be debate, some fierce... :) Having been a fan of the later since varsity, I have recently seen the light and converted to being a fan of the former. On the suggestion of a good friend, I experimented with it in a recent project and have seen the error of my ways. I find the former to more clearly show 'blocks' of code, and thus to be far more readable and maintainable. Having just said that, it did take me a week or two to get used to it though. I work on several projects, using both styles. My only real comment is that consistency is more important and that always seems to be the common point people make. Long live OTBS... :)

                                      J 1 Reply Last reply
                                      0
                                      • N N a v a n e e t h

                                        Which one you prefer ?

                                        if{
                                        //do something
                                        }

                                        Or

                                        if
                                        {
                                        //do something
                                        }


                                        printf("Navaneeth!!") www.w3hearts.com

                                        K Offline
                                        K Offline
                                        Kevin McFarlane
                                        wrote on last edited by
                                        #24

                                        Oh, no. Not another religious war! :omg: Second.

                                        Kevin

                                        1 Reply Last reply
                                        0
                                        • D Dario Solera

                                          The real problem with braces is not the style itself, but different styles in the same project, or even file. Most IDEs can reformat the code, but that way there are a few problems with source control... BTW, I prefer this:

                                          if(true) {
                                          // Blah
                                          }

                                          If you truly believe you need to pick a mobile phone that "says something" about your personality, don't bother. You don't have a personality. A mental illness, maybe - but not a personality. - Charlie Brooker My Blog - My Photos - ScrewTurn Wiki

                                          K Offline
                                          K Offline
                                          Kevin McFarlane
                                          wrote on last edited by
                                          #25

                                          Dario Solera wrote:

                                          different styles in the same project, or even file.

                                          Yeah, that sucks.

                                          Kevin

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups