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. What are your curly-bracing style?

What are your curly-bracing style?

Scheduled Pinned Locked Moved The Lounge
cssjavaadobequestion
99 Posts 49 Posters 0 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 Nikunj_Bhatt

    Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:

    if(a>b)
    { // sometimes i write comment here about logic and parameters etc.
    print "b is less than or equal to a"
    print "it means a is greater than b"
    }
    else
    print "a is either either equal to or less than b"

    Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:

    if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
    print "b is less than or equal to a"
    print "it means a is greater than b"
    } else {
    print "a is either either equal to or less than b"
    }

    if(a>b)
    {
    print "b is less than or equal to a"
    print "it means a is greater than b"
    }
    else
    {
    print "a is either either equal to or less than b"
    }

    if(a>b)
    { print "b is less than or equal to a"
    print "it means a is greater than b"
    }

    P Offline
    P Offline
    Peter Mulholland
    wrote on last edited by
    #38

    I hope I never have to maintain any code you've written. This:

    nikunjbhatt84 wrote:

    if(a>b)

    is just wrong. Use some whitespace!

    if (a > b)
    {
    }

    Pete

    P N 2 Replies Last reply
    0
    • N Nikunj_Bhatt

      Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:

      if(a>b)
      { // sometimes i write comment here about logic and parameters etc.
      print "b is less than or equal to a"
      print "it means a is greater than b"
      }
      else
      print "a is either either equal to or less than b"

      Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:

      if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
      print "b is less than or equal to a"
      print "it means a is greater than b"
      } else {
      print "a is either either equal to or less than b"
      }

      if(a>b)
      {
      print "b is less than or equal to a"
      print "it means a is greater than b"
      }
      else
      {
      print "a is either either equal to or less than b"
      }

      if(a>b)
      { print "b is less than or equal to a"
      print "it means a is greater than b"
      }

      J Offline
      J Offline
      Jonas Hammarberg
      wrote on last edited by
      #39

      I used alt 2 for many years as it made it easy to see any missing code. These days I use condition { statement } condition { statement } Occasionally I use one-liners, eg. when it's just an test before one statement (two statement and there comes the curlies flying} As there are "prettifiers" available in most editors these days the subject is mot. Decide on one standard that all code should be formatted by before checking in and use what ever that makes you comfortable while coding.

      1 Reply Last reply
      0
      • S Soulus83

        Code block is so long I can't see the voting bar! This is my preferred style:

        if(a>b)
        {
        print "b is less than or equal to a";
        print "it means a is greater than b";
        }

        Each curly brace on it's own line, don't know why but it helps me read the code :confused:

        T Offline
        T Offline
        tom1443
        wrote on last edited by
        #40

        I second that!

        1 Reply Last reply
        0
        • C Colin Rae

          The proper way.

          if (something){
              do stuff
              do more stuff
          }
          else{
              do something different
          }
          

          Am I showing my age if I mention Kernighan and Ritchie? :)

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

          Maybe, but IIRC K&R wrote their manuscript using this style originally:

          if (something)
          {
          do stuff
          do more stuff
          }
          else
          {
          do something different
          }

          It was changed at the publishers request to save on printing costs.

          3x12=36 2x12=24 1x12=12 0x12=18

          P 1 Reply Last reply
          0
          • N Nikunj_Bhatt

            Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:

            if(a>b)
            { // sometimes i write comment here about logic and parameters etc.
            print "b is less than or equal to a"
            print "it means a is greater than b"
            }
            else
            print "a is either either equal to or less than b"

            Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:

            if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
            print "b is less than or equal to a"
            print "it means a is greater than b"
            } else {
            print "a is either either equal to or less than b"
            }

            if(a>b)
            {
            print "b is less than or equal to a"
            print "it means a is greater than b"
            }
            else
            {
            print "a is either either equal to or less than b"
            }

            if(a>b)
            { print "b is less than or equal to a"
            print "it means a is greater than b"
            }

            A Offline
            A Offline
            AdamEcc
            wrote on last edited by
            #42

            if(a>b)
            {
            print "b is less than or equal to a"
            print "it means a is greater than b"
            }
            else
            {
            print "a is either either equal to or less than b"
            }

            With the exception of single-statement getters/setters, in which case

            public int SomeProperty
            {
            get{return somePropertyValue;}
            set
            {
            if (value != somePropertyValue)
            {
            someProperty = value;
            // raise value changed event
            }
            }
            }

            I like that putting the open brace under the function / operation name makes it easy to spot where braces match up, but think it looks clunky when you only have a single line in a getter / setter.

            1 Reply Last reply
            0
            • N Nikunj_Bhatt

              Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:

              if(a>b)
              { // sometimes i write comment here about logic and parameters etc.
              print "b is less than or equal to a"
              print "it means a is greater than b"
              }
              else
              print "a is either either equal to or less than b"

              Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:

              if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
              print "b is less than or equal to a"
              print "it means a is greater than b"
              } else {
              print "a is either either equal to or less than b"
              }

              if(a>b)
              {
              print "b is less than or equal to a"
              print "it means a is greater than b"
              }
              else
              {
              print "a is either either equal to or less than b"
              }

              if(a>b)
              { print "b is less than or equal to a"
              print "it means a is greater than b"
              }

              R Offline
              R Offline
              R Erasmus
              wrote on last edited by
              #43

              Nothing beats this, I'm sorry ;(

              if (a > b)
              {
              /* Code */
              }
              else if (c == d)
              {
              /* Code */
              }
              else
              {
              /* Code */
              }

              "Program testing can be used to show the presence of bugs, but never to show their absence." << please vote!! >>

              1 Reply Last reply
              0
              • N Nikunj_Bhatt

                Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:

                if(a>b)
                { // sometimes i write comment here about logic and parameters etc.
                print "b is less than or equal to a"
                print "it means a is greater than b"
                }
                else
                print "a is either either equal to or less than b"

                Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:

                if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
                print "b is less than or equal to a"
                print "it means a is greater than b"
                } else {
                print "a is either either equal to or less than b"
                }

                if(a>b)
                {
                print "b is less than or equal to a"
                print "it means a is greater than b"
                }
                else
                {
                print "a is either either equal to or less than b"
                }

                if(a>b)
                { print "b is less than or equal to a"
                print "it means a is greater than b"
                }

                D Offline
                D Offline
                Dale Barnard
                wrote on last edited by
                #44

                I've seen so many developers (especially newer ones) obsess over code syntactic readability, but I have found that I can get used to any style. My mental focus is mainly on code design (class, method, static definitions, etc.) more than the syntactic details. I would write try { myField = new Field(...); } catch { report error } because at a design level, it is only one logical statement. The error handing in this case is related to that statement, so I kept it on the same line. If it takes two steps to do something, I'll spread out the code to more lines: try { myField = new Field(...); myField.Event += event handler; } catch { report error }; Still, my focus is not on seeing (or obsessing over) curly braces, but rather on seeing the logical steps going on. I want the curly braces to drift into the background. I'm a contractor, so I match the style used by each employer, and I adapt pretty quickly to whatever they do, no matter how illogical. I don't let myself obsess over syntax, so once I get used to a style, those curly braces just disappear from my view, leaving the logical structure. When code has inconsistent syntax (such as each developer using a unique style), I can't help but notice the syntax, distracting me from higher-level design. Thus, the most important thing for me is CONSISTENCY.

                J 1 Reply Last reply
                0
                • N Nikunj_Bhatt

                  Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:

                  if(a>b)
                  { // sometimes i write comment here about logic and parameters etc.
                  print "b is less than or equal to a"
                  print "it means a is greater than b"
                  }
                  else
                  print "a is either either equal to or less than b"

                  Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:

                  if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
                  print "b is less than or equal to a"
                  print "it means a is greater than b"
                  } else {
                  print "a is either either equal to or less than b"
                  }

                  if(a>b)
                  {
                  print "b is less than or equal to a"
                  print "it means a is greater than b"
                  }
                  else
                  {
                  print "a is either either equal to or less than b"
                  }

                  if(a>b)
                  { print "b is less than or equal to a"
                  print "it means a is greater than b"
                  }

                  S Offline
                  S Offline
                  Stuart Rubin
                  wrote on last edited by
                  #45

                  First of all, I'm happy to read this forum and not see too many "religious" arguments for styling one way or another! There are good, objective reasons to use different styles. I always go back to McConnell's "Code Complete." Chapter 31 is all about layout and style. Basically, the layout style needs to address these. I'm quoting headings from the book: Accurately represent the logical structure of the code Consistently represent the logical structure of the code Improve readability Withstand modification I think the first two are obvious. The latter two are what require the thought. Personally, I'm a white-space-supremacist bracist (good pun, earlier poster!), and like:

                  // Check for matching data results
                  if(a == b)
                  {
                  // The data match.
                  doSomething();
                  }
                  else if (a == c)
                  {
                  // Something else matched
                  doSomethingElse();
                  }
                  else
                  {
                  // Something may have gone wrong.
                  doErrorCode();
                  }

                  The blocks are easily identifiable. It's almost impossible to screw up when you add code. It's also easy to comment; the comments naturally identify the blocks.

                  1 Reply Last reply
                  0
                  • N Nikunj_Bhatt

                    Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:

                    if(a>b)
                    { // sometimes i write comment here about logic and parameters etc.
                    print "b is less than or equal to a"
                    print "it means a is greater than b"
                    }
                    else
                    print "a is either either equal to or less than b"

                    Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:

                    if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
                    print "b is less than or equal to a"
                    print "it means a is greater than b"
                    } else {
                    print "a is either either equal to or less than b"
                    }

                    if(a>b)
                    {
                    print "b is less than or equal to a"
                    print "it means a is greater than b"
                    }
                    else
                    {
                    print "a is either either equal to or less than b"
                    }

                    if(a>b)
                    { print "b is less than or equal to a"
                    print "it means a is greater than b"
                    }

                    S Offline
                    S Offline
                    Stefan_Lang
                    wrote on last edited by
                    #46

                    if (you_had_asked_me_10_years_ago)
                    {
                    I_would_have_done_it = this_way;
                    }
                    else
                    {
                    see = below;
                    }

                    if (you_ask_me_now) {
                    that = what_I_prefer_now;
                    }
                    else {
                    what=ever;
                    }

                    My main reasons are: 1. optical readability through indentation - all the actual code belonging to the block is indented 2. the ending '}' is easier to find when it's not indented with the block 3. there is no reason to start a new line for an opening '{' since the statement causing the new control block already is signal enough, and optically starts the block because of the indentation in the following line(s) 4. I always use curly brackets, even if there's only one line. (a) This way I better recognize that there is some kind of control flow even when the indentation is messed up. (b) Also, in my experience most one-line blocks won't stay one-liners for long. (c) And I also get some consistentency with control commands, as they'll always take one line to start a block and one line (the '}' on a seperate line) to end. Of course, much of this is a matter of taste, but after trying several styles over the past 25 years, this is what pleases me most.

                    1 Reply Last reply
                    0
                    • R Ravi Bhavnani

                      Heh.  You'll probably get as many responses as there are developers.  Or religions. :) I prefer the Java style because it allows me to see more code using a shorter display.  But when I'm editing code written by another developer, I adhere to his/her style. /ravi

                      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                      N Offline
                      N Offline
                      Nemanja Trifunovic
                      wrote on last edited by
                      #47

                      Ravi Bhavnani wrote:

                      the Java style

                      That would be K&R style :)

                      utf8-cpp

                      R 1 Reply Last reply
                      0
                      • S Soulus83

                        Code block is so long I can't see the voting bar! This is my preferred style:

                        if(a>b)
                        {
                        print "b is less than or equal to a";
                        print "it means a is greater than b";
                        }

                        Each curly brace on it's own line, don't know why but it helps me read the code :confused:

                        J Offline
                        J Offline
                        jsc42
                        wrote on last edited by
                        #48

                        I, too, align left and right braces under their base keyword. I have done this since I learnt Algol 60 which predates the C family of languages and had begin and end rather than { and }. When I learnt Pascal, which overloaded the end keyword, I added another convention: Add an end-of-construct comment. Labels (e.g. for switch cases) are aligned with the braces and the code that they point to is on another line indented from the brace. Typical fragments (not working code):

                        if (discr > 0)
                        {
                        // Work out real roots
                        ...
                        } // if
                        else if (discr < 0)
                        {
                        // Work out imaginary roots
                        ...
                        } // else if
                        else // Equal roots
                        switch (dayOfWeek)
                        {
                        case Sat:
                        case Sun:
                        alert('Equal roots at the weekend - take the day off');
                        break;

                        case Wed:
                        alert('Mid week with equal roots - take a nap');
                        break;

                        default:
                        alert('Do unpaid overtime');
                        break;
                        } // switch

                        No, I do not brace single statement; and yes, I do treat else if as though it were a keyword even though it is not in most languages. Let the flame wars commence. Does anyone know how to insert blank lines in code samples?

                        M 1 Reply Last reply
                        0
                        • N Nikunj_Bhatt

                          Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:

                          if(a>b)
                          { // sometimes i write comment here about logic and parameters etc.
                          print "b is less than or equal to a"
                          print "it means a is greater than b"
                          }
                          else
                          print "a is either either equal to or less than b"

                          Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:

                          if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
                          print "b is less than or equal to a"
                          print "it means a is greater than b"
                          } else {
                          print "a is either either equal to or less than b"
                          }

                          if(a>b)
                          {
                          print "b is less than or equal to a"
                          print "it means a is greater than b"
                          }
                          else
                          {
                          print "a is either either equal to or less than b"
                          }

                          if(a>b)
                          { print "b is less than or equal to a"
                          print "it means a is greater than b"
                          }

                          P Offline
                          P Offline
                          Peter_Olson
                          wrote on last edited by
                          #49

                          This doesn't relate to the curly braces, but your logic is incorrect. If a>b, b cannot be equal to a. Thus, "b is less than or equal to a" does not mean the same thing as "a is greater than b".

                          N 1 Reply Last reply
                          0
                          • S Soulus83

                            Code block is so long I can't see the voting bar! This is my preferred style:

                            if(a>b)
                            {
                            print "b is less than or equal to a";
                            print "it means a is greater than b";
                            }

                            Each curly brace on it's own line, don't know why but it helps me read the code :confused:

                            F Offline
                            F Offline
                            Frank Peelo
                            wrote on last edited by
                            #50

                            it's obvious why. The braces are used to mark the start and end of a block, and you have them here in the same column (so your eye knows where to go to look for it) and without hiding them in other text. This is obviously a good style for this language. If you, or the person who taught you, or (the person who taught)^n you comes from a language where keywords delimit blocks, then you could end up with the style where braces are placed on the same line as the keyword. So if (a>b) ... blah ... else ... blah ... endif becomes if (a>b) { ... blah ... } else { ... blah ... } This is clearly inappropriate behaviour in the latter case because the keywords here do not delimit the block. The braces do, but they are made more difficult to find. It is appropriate in the other language, because the keywords which delimit the block are in the same column and are not hidden in other text.

                            1 Reply Last reply
                            0
                            • L Lost User

                              If your tool is f*cked it's time to get a new tool.

                              ___________________________________________ .\\axxx (That's an 'M')

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

                              The tool is fine. I just need to use it in accordance with its rules. edlin, on the other hand...

                              1 Reply Last reply
                              0
                              • S Soulus83

                                Code block is so long I can't see the voting bar! This is my preferred style:

                                if(a>b)
                                {
                                print "b is less than or equal to a";
                                print "it means a is greater than b";
                                }

                                Each curly brace on it's own line, don't know why but it helps me read the code :confused:

                                S Offline
                                S Offline
                                spencepk
                                wrote on last edited by
                                #52

                                Same here

                                1 Reply Last reply
                                0
                                • N Nemanja Trifunovic

                                  Ravi Bhavnani wrote:

                                  the Java style

                                  That would be K&R style :)

                                  utf8-cpp

                                  R Offline
                                  R Offline
                                  Ravi Bhavnani
                                  wrote on last edited by
                                  #53

                                  Yes, exactly!  I still have my circa 1981 copy of K&R! :) /ravi

                                  My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                                  G 1 Reply Last reply
                                  0
                                  • N Nikunj_Bhatt

                                    Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:

                                    if(a>b)
                                    { // sometimes i write comment here about logic and parameters etc.
                                    print "b is less than or equal to a"
                                    print "it means a is greater than b"
                                    }
                                    else
                                    print "a is either either equal to or less than b"

                                    Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:

                                    if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
                                    print "b is less than or equal to a"
                                    print "it means a is greater than b"
                                    } else {
                                    print "a is either either equal to or less than b"
                                    }

                                    if(a>b)
                                    {
                                    print "b is less than or equal to a"
                                    print "it means a is greater than b"
                                    }
                                    else
                                    {
                                    print "a is either either equal to or less than b"
                                    }

                                    if(a>b)
                                    { print "b is less than or equal to a"
                                    print "it means a is greater than b"
                                    }

                                    D Offline
                                    D Offline
                                    dpminusa
                                    wrote on last edited by
                                    #54

                                    Alt 2, since this is what the if snippet produces. I try to use all the snippet templates. As mentioned it can produce auto indenting on some editors, e.g. Komodo. Komodo also has code folding that helps emphasize the scope areas.

                                    "Courtesy is the product of a mature, disciplined mind ... ridicule is lack of the same - DPM"

                                    1 Reply Last reply
                                    0
                                    • P PIEBALDconsult

                                      _Maxxx_ wrote:

                                      whatever indentation you (each) like

                                      Edit and Notepad insist on 8. X| And, even the otherwise fine Xacc.IDE doesn't adjust indents properly. (When last I tried.)

                                      J Offline
                                      J Offline
                                      Jim SS
                                      wrote on last edited by
                                      #55

                                      Notepad++ has replaced my notepad for all but the simplest views.

                                      SS => Qualified in Submarines "We sleep soundly in our beds because rough men stand ready in the night to visit violence on those who would do us harm". Winston Churchill "Real programmers can write FORTRAN in any language". Unknown

                                      P 1 Reply Last reply
                                      0
                                      • N Nikunj_Bhatt

                                        Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:

                                        if(a>b)
                                        { // sometimes i write comment here about logic and parameters etc.
                                        print "b is less than or equal to a"
                                        print "it means a is greater than b"
                                        }
                                        else
                                        print "a is either either equal to or less than b"

                                        Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:

                                        if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
                                        print "b is less than or equal to a"
                                        print "it means a is greater than b"
                                        } else {
                                        print "a is either either equal to or less than b"
                                        }

                                        if(a>b)
                                        {
                                        print "b is less than or equal to a"
                                        print "it means a is greater than b"
                                        }
                                        else
                                        {
                                        print "a is either either equal to or less than b"
                                        }

                                        if(a>b)
                                        { print "b is less than or equal to a"
                                        print "it means a is greater than b"
                                        }

                                        J Offline
                                        J Offline
                                        Jim SS
                                        wrote on last edited by
                                        #56

                                        I vote for getting rid of braces and using indentation exclusively. Using braces the way many people do causes too many wasted lines (empty of anything useful).

                                        SS => Qualified in Submarines "We sleep soundly in our beds because rough men stand ready in the night to visit violence on those who would do us harm". Winston Churchill "Real programmers can write FORTRAN in any language". Unknown

                                        P 1 Reply Last reply
                                        0
                                        • N Nikunj_Bhatt

                                          Which method do u use for curly braces to create scope of a programming structure? I mostly prefer this method:

                                          if(a>b)
                                          { // sometimes i write comment here about logic and parameters etc.
                                          print "b is less than or equal to a"
                                          print "it means a is greater than b"
                                          }
                                          else
                                          print "a is either either equal to or less than b"

                                          Note that, I don't use braces for a single line of scope and I indent the starting brace and ending brace and it is not on the same line where the control structure is defined. I use this approach because it makes easy (just hit Enter key, no need to press Tab key) to add a new line of code after the staring brace and before the first statement of the block. I use Notepad++ and it has slightly good matching braces hilting feature and this method helps to correctly lineup and identify scope content. Here are some more methods used my many programmers:

                                          if(a>b) { // this is Flash's ActionScript's default formatting, I hate this style the most, I feel it most unreadable, some Java programmers and web designers working on CSS also use almost similar method for writing CSS rules
                                          print "b is less than or equal to a"
                                          print "it means a is greater than b"
                                          } else {
                                          print "a is either either equal to or less than b"
                                          }

                                          if(a>b)
                                          {
                                          print "b is less than or equal to a"
                                          print "it means a is greater than b"
                                          }
                                          else
                                          {
                                          print "a is either either equal to or less than b"
                                          }

                                          if(a>b)
                                          { print "b is less than or equal to a"
                                          print "it means a is greater than b"
                                          }

                                          P Offline
                                          P Offline
                                          patbob
                                          wrote on last edited by
                                          #57

                                          Why not just go with whatever Visual Studio does when you use Ctrl-K Ctrl-F to reformat/reindent a block of code?

                                          patbob

                                          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