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

    I'm even more anal about bracing. I use if(blah) { stuff even if only one line. Notice the indent; } That way I can line up the if, else etc and eyeball for closing braces to see which block the code is in. I find: if(blah) { dgf dfd df df fdf dfdf } else { dfd df df dsf dg } method annoying. You are forced to look at the first character of each line to see if it is the brace your looking for, rather than scan down the column where the brace your looking for should be.

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

    Oh crap, I got slaughtered by white space removal. The buggers ;) Corrected if(blah) { stuff even if one line. Notice the indent. }

    D 1 Reply Last reply
    0
    • D deltalmg

      Oh crap, I got slaughtered by white space removal. The buggers ;) Corrected if(blah) { stuff even if one line. Notice the indent. }

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

      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 1 Reply Last reply
      0
      • C Craig Atwood

        This is interesting, I myself used the latter, but in the programming course Ive done they teach using the former, although Ive gotten used to programming like that i still dont like it and prefer having the extra line breaks

        D Offline
        D Offline
        DavidGB
        wrote on last edited by
        #106

        Yes, this IS interesting. It weems we were all taught the K&R style, yet aklmost all of us (myself included) have come to prefer the "latter" style. Should we be asking for another revision of K&R? Would anybody pay any attention to it anyway? David

        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
          patbob
          wrote on last edited by
          #107

          Prefer? My preference is irrelevant. The ancients said it best.. when in Rome, do as the Romans. When in someone else's code, match their style. Unless you're writing C#, in which case, Caesar Gates's cronies have decreed how we will all do our braces, spacing and indentation. Fine, whatever, we've all got more important things to do than to fight it anyway.. right? After 20 or so years of reading all different brace styles, you'll pretty much cease to see them anyway.. as long as it is consistent throughout a file. Remember, Rome-Romans. What should you do in completely new files? Sure, fine, whatever. Which do I do in new files? The second one. Why? Because I was asked to. Why was I asked to? I dunno, probably because someone had a harder time of understanding the code with the first one. Why do I bother to comply? Because they claim it helps them.

          patbob

          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
            M i s t e r L i s t e r
            wrote on last edited by
            #108

            How about letting the development environment decide based on who you are... that way if you like it one way and your colleague likes it formatted another way, you both can have your cake and eat it too.

            1 Reply Last reply
            0
            • 1 123 0

              [Message Deleted]

              J Offline
              J Offline
              Jasmine2501
              wrote on last edited by
              #109

              I don't like extra line breaks. I've been reading code for many years and I don't need the visual noise. I like things in a smaller space. I leave out braces for single-statement blocks, and I love the (x ? y : z) notation. It's a non-issue though, because VS can quickly re-format code to your personal style. It takes a bit of fiddling with the options, but you can get whatever you want out of it.

              "Quality Software since 1983!"
              http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

              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

                L Offline
                L Offline
                Lilith C
                wrote on last edited by
                #110

                Mixed. For functions I use the latter. For blocks inside functions? The former. Lilith

                1 Reply Last reply
                0
                • 1 123 0

                  [Message Deleted]

                  A Offline
                  A Offline
                  Al Chambers
                  wrote on last edited by
                  #111

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

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