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.
  • 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

    M Offline
    M Offline
    Member 96
    wrote on last edited by
    #112

    Yes!


    "110%" - it's the new 70%

    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

      M Offline
      M Offline
      Member 96
      wrote on last edited by
      #113

      If you have an ounce of artistry in your soul as a programmer you would use the latter. The first one drives me nuts, it just screams out to me to be dropped down to the latter style. I find the visual style and symmetry of code to be equally important as comments in understanding it and life is to short to play "match the braces" when editing existing code. Every block of code should be indented from it's surrounding block and the opening and closing characters should be on the same column.


      "110%" - it's the new 70%

      1 Reply Last reply
      0
      • D deltalmg

        Thats crazy, even marking it as code this site doesn't keep your formating. Whoever coded this webform is going to go to scripting hell. Every thing he codes will be parsed and emulated on a Comandor 64, no native code for you:laugh:

        D Offline
        D Offline
        Dan Neely
        wrote on last edited by
        #114

        The pre tag is what you want. code is only intended for a small snippet of code in the middle of plain text. Yes it is confusing. :mad:

        -- You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer

        D 1 Reply Last reply
        0
        • D Dan Neely

          The pre tag is what you want. code is only intended for a small snippet of code in the middle of plain text. Yes it is confusing. :mad:

          -- You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer

          D Offline
          D Offline
          deltalmg
          wrote on last edited by
          #115

          Oh, the pre tag of course:mad: Thanks.

          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

            C Offline
            C Offline
            ClockMeister
            wrote on last edited by
            #116

            if (condition) then do something endif -CB :)

            1 Reply Last reply
            0
            • M Muhadeeb99

              As far as "proper" I sorta meant it as a tongue in cheek remark. The style to which one uses brace formatting is really up to the user. It has its merits either way.

              All things being equal, tommorrow will never equal today

              J Offline
              J Offline
              JimAtImpac
              wrote on last edited by
              #117

              I prefer the former, but VS 2005 forces me to use the latter. Everyone in my company uses VS 2005 so I have to use the same style to be consistent. Jim

              S 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

                J Offline
                J Offline
                jschell
                wrote on last edited by
                #118

                Claiming that one style is more "readable" than other is a loaded subjective word with no objective evidence to justify it.

                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/[^]

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #119

                  Frank Kerrigan wrote:

                  Last one complies to coding standards

                  And if the coding standard said to jump off a bridge?

                  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
                    PIEBALDconsult
                    wrote on last edited by
                    #120

                    All paired items (braces, brackets, parentheses, quotes, and "angle-brackets") (and commas within a list) should be aligned either horizontally or vertically.

                    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

                      J Offline
                      J Offline
                      JWWicks
                      wrote on last edited by
                      #121

                      Shog9 wrote:

                      used only by miscreants and rogues

                      Sign me up in the miscreants and rogues class... Computers are useless, they can only give you answers...- Pablo Picasso John

                      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
                        Keith Barrett
                        wrote on last edited by
                        #122

                        I have a scientific(ish) test for this. * Print out a sample of code on A4 paper in 10 point courier font. * Stick it to the wall * Stand several metres away (more if you have good eyesight) * If you can still clearly discern the structure of the code then you have a good layout style

                        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

                          T Offline
                          T Offline
                          tomasorti
                          wrote on last edited by
                          #123

                          Well, it depends on the context, code, tool used, etc... Sometimes one can be more suitable than the other. For example, when functions are larger than a page, if you position in the closing brace, (X)Emacs helps you and prints in the minibuffer the matched opening brace. If you use the former (e.g.: if (x == 0) { ) it is helpful. I'm sure you can find pros and cons for both. Just my 2 cents, Tomas

                          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
                            nilotic
                            wrote on last edited by
                            #124

                            it doesn't really matter UNLESS you're nesting loops like a madman. My first script (almost 900 lines) had about 16 nested loops (ie. 16 deep !) and it obviously hurt like hell trying to debug it. I just wrote it without any planning or consideration for separating tasks into modules or even routines. Looking back, I am amazed I wasn't quietly assassinated by the programmer who had to check it over when I began running it at work, on the live system. Anyway, I converted to the latter style (braces on new lines) because it gave me that little bit of help seeing the blocks/scopes. modern IDE's have a beautify option so it doesn't matter anymore. Wish I'd known that back then. I'm considering starting a thread about 'my first script..was shocking' because it does get funnier the more I think about it.....but I can't find the option to 'start a new thread'. Do I just 'reply' but change the subject field?

                            'All there really is, is: virtue and vice' ...Black Crowes

                            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

                              E Offline
                              E Offline
                              Ed K
                              wrote on last edited by
                              #125

                              Prefer the latter and require them. Too many bugs find their way into the code without.

                              ed ~"Watch your thoughts; they become your words. Watch your words they become your actions. Watch your actions; they become your habits. Watch your habits; they become your character. Watch your character; it becomes your destiny." -Frank Outlaw.

                              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

                                S Offline
                                S Offline
                                SouthRoss
                                wrote on last edited by
                                #126

                                Gotta say, I prefer the latter for two reasons 1.)because I can place the cursor next to one brace and find the matching one just by using the up/down arows on my keyboard. works with any text file editor, syntax aware or not (even notepad) 2.) there are occasions where want to remove the condition but keep the code block eg // if (condition) { // do something } Easy to achieve either way of course, but just that little bit easier the second way (because you only need to "play" with one line. Having said that, the company I work for uses the first method, so I'm pretty much stuck with it. After the first 5 minutes using a particular style professionals will get used to it. If someones skills are that shaky that "weird" braces cause them to melt down, they'd probably want to be brushing up on those software engineering 101 skills...:laugh: Karl

                                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

                                  V Offline
                                  V Offline
                                  Vikram A Punathambekar
                                  wrote on last edited by
                                  #127

                                  Dario Solera wrote:

                                  The real problem with braces is not the style itself, but different styles in the same project, or even file.

                                  There was this guy I knew.... :^)

                                  Dario Solera wrote:

                                  BTW, I prefer this: if(true) { // Blah }

                                  You have disappointed me. Prepare to die....

                                  Cheers, Vıkram.


                                  Déjà moo - The feeling that you've seen this bull before. Join the CP group at NationStates. Password: byalmightybob

                                  D 1 Reply Last reply
                                  0
                                  • V Vikram A Punathambekar

                                    Dario Solera wrote:

                                    The real problem with braces is not the style itself, but different styles in the same project, or even file.

                                    There was this guy I knew.... :^)

                                    Dario Solera wrote:

                                    BTW, I prefer this: if(true) { // Blah }

                                    You have disappointed me. Prepare to die....

                                    Cheers, Vıkram.


                                    Déjà moo - The feeling that you've seen this bull before. Join the CP group at NationStates. Password: byalmightybob

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

                                    Vikram A Punathambekar wrote:

                                    You have disappointed me.

                                    :zzz:

                                    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

                                    V 1 Reply Last reply
                                    0
                                    • A Al Chambers

                                      My favourite (probably) apocryphal story on this point is that K&R used their style for no other reason that to save space (and thus publishing costs) in their book. I sooo want this to be true. What about this one: if (something) { do_something(); } While we're at it... Tabs or spaces? :-)

                                      J Offline
                                      J Offline
                                      JMOdom
                                      wrote on last edited by
                                      #129

                                      I have seen one classmate of mine type code in the following manner: if (something){do_something();} Its ok i suppose if it isn't to long. ;P

                                      1 Reply Last reply
                                      0
                                      • D Dario Solera

                                        Vikram A Punathambekar wrote:

                                        You have disappointed me.

                                        :zzz:

                                        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

                                        V Offline
                                        V Offline
                                        Vikram A Punathambekar
                                        wrote on last edited by
                                        #130

                                        :laugh: I suppose I should have included the 'joke' marker. ;)

                                        Cheers, Vıkram.


                                        Déjà moo - The feeling that you've seen this bull before. Join the CP group at NationStates. Password: byalmightybob

                                        1 Reply Last reply
                                        0
                                        • J John R Shaw

                                          The space is not big deal, but I like consistency and placing that space suggests to me that a space should be place before every ‘(‘ character. When I started programming (in C) using ‘++i’ as apposed to ‘i++’ was a very minor optimization, as the compilers did not do the optimization for you. In C it was not really that important, even when the machines where slow, but is C++ it can make a big difference. As you noted “Most of the time it makes no difference”, but if you make it a habit and teach others to do the same thing, which most books do now, then they are learning the wrong thing. Even Bjarne Stroustrup uses ‘++i’ instead of ‘i++’ although I have never read a statement by him as to why he does that. But other experts on the language have explained it in detail.

                                          INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra

                                          C Offline
                                          C Offline
                                          Craig Atwood
                                          wrote on last edited by
                                          #131

                                          as far as if() with or without a space in between i dont care but the difference between "i++" and "++i" is... i++ = returns the value of 'i' before it was incremented ++i = returns the value of 'i' after it was incremented e.g

                                          int i = 1;
                                          if(++i == 2)
                                          {
                                          thisWillWork();
                                          }
                                          //
                                          //OR
                                          //
                                          int i = 1;
                                          if(i++ == 2)
                                          {
                                          thisWontWork();
                                          }

                                          This is what the operators do and you can use them bassed on what you need your code to do. if you use them correctly you can end up saving a few lines of code:cool: ps. as to my brace style brace on next line = more readable thats my vote

                                          J 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