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 11 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 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
      • G grgran

        God of course intended that there be only one bracing style. All other expose one as a programmer who has fallen from the path. The pattern for an 'if' is as follows:

        if (conditional) { // waste not, want not: don't waste vertical space
        statement(s) // note the indention, this clearly identifies these statements as
        // belonging to the if
        } // note the indention again, this closes the if logic, it is the
        // end of the existing block, not the beginning of a new one

        Of course heritics abound, but my place in "code vault store" is assured (ya have to be a fan of STTNG Klingon afterlife to get that one). Go forth and spread the glad tiding and good bracings and do not hesitate to cntl-K cntl-D the code of the unbelievers. ;):laugh: Brace Zealot -- modified at 11:16 Thursday 17th May, 2007

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

        BLASPHEMY!!!!:omg: indenting the closing brace *-Shudder-* u r a Patagh

        G 1 Reply Last reply
        0
        • D Dan Neely

          grgran wrote:

          Of course heritics abound, but my place in "code vault store"

          Brandishes steel cored foam cluebat. *BIFFF* *BIFFF* *BIFFF* *BIFFF* *BIFFF* *BIFFF* *BIFFF* *BIFFF*

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

          G Offline
          G Offline
          grgran
          wrote on last edited by
          #133

          Don't you mean a foam clue-batleth LOL

          1 Reply Last reply
          0
          • C Craig Atwood

            BLASPHEMY!!!!:omg: indenting the closing brace *-Shudder-* u r a Patagh

            G Offline
            G Offline
            grgran
            wrote on last edited by
            #134

            Do not fear brother. One day you shall be brought into light, cleansed and purified. Then you can find the true joy known only by those who indent our closing braces. Convert now and do not risk an afterlife protected by Fek'lhr.

            C 1 Reply Last reply
            0
            • R R_L_H

              [Message Deleted]

              U Offline
              U Offline
              urbane tiger
              wrote on last edited by
              #135

              what about delegates, how do folks brace those? On other things I use brace-on-line, unless I put content on same line eg - case Monday : { DoWork(); break; }. Before I started using IDE's I always used K&R style, but tubes were smaller then, so whether it's IDE's or screen size I dunno,: sigh: could be age philD

              1 Reply Last reply
              0
              • G grgran

                Do not fear brother. One day you shall be brought into light, cleansed and purified. Then you can find the true joy known only by those who indent our closing braces. Convert now and do not risk an afterlife protected by Fek'lhr.

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

                MORE BLASPHEMY!!! the true if is as follows

                if(condition)
                {
                doStuff();
                }
                else
                {
                doSomethingElse();
                }

                Your Brace style bears the identifiable stench of a Vagabond Romulan coder, May Fek'lhr forgive your dishonour.

                G 1 Reply Last reply
                0
                • C Craig Atwood

                  MORE BLASPHEMY!!! the true if is as follows

                  if(condition)
                  {
                  doStuff();
                  }
                  else
                  {
                  doSomethingElse();
                  }

                  Your Brace style bears the identifiable stench of a Vagabond Romulan coder, May Fek'lhr forgive your dishonour.

                  G Offline
                  G Offline
                  grgran
                  wrote on last edited by
                  #137

                  Don't make me say something about yo momma ;-) :-D

                  1 Reply Last reply
                  0
                  • C Craig Atwood

                    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 Offline
                    J Offline
                    John R Shaw
                    wrote on last edited by
                    #138

                    I have been away, but that is not the only difference in C++. For integral types (int, etc…) they can be optimized by the compiler (no function call occurring). When working with class objects it requires a copy of the original to be made, then an increment of the original, and then a return of a temporary object (another copy). That can be a lot of processing for a simple increment and therefore using ‘i++’ instead of ‘++i’ is a bad habit that should be avoided. Note: A non-optimizing C compiler would go through the same steps, but the temporary and return value where usually in the same register, and therefore copying was minimal. P.S. Look it up in puzzle books and other books on optimizing. Or just write a class that requires memory allocation and supports the ‘++’ operator in both pre and post forms and you will see the possible problems.

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

                    C 1 Reply Last reply
                    0
                    • J John R Shaw

                      I have been away, but that is not the only difference in C++. For integral types (int, etc…) they can be optimized by the compiler (no function call occurring). When working with class objects it requires a copy of the original to be made, then an increment of the original, and then a return of a temporary object (another copy). That can be a lot of processing for a simple increment and therefore using ‘i++’ instead of ‘++i’ is a bad habit that should be avoided. Note: A non-optimizing C compiler would go through the same steps, but the temporary and return value where usually in the same register, and therefore copying was minimal. P.S. Look it up in puzzle books and other books on optimizing. Or just write a class that requires memory allocation and supports the ‘++’ operator in both pre and post forms and you will see the possible problems.

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

                      I didnt know that it did that with class objects thanx very usefull

                      1 Reply Last reply
                      0
                      • J JimAtImpac

                        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 Offline
                        S Offline
                        SimonRigby
                        wrote on last edited by
                        #140

                        VS2005 doesn't force you. That can be changed in options. However, house style is of course a different matter :)

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

                        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