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

Braces.

Scheduled Pinned Locked Moved The Lounge
testingbeta-testinghelp
20 Posts 17 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.
  • OriginalGriffO OriginalGriff

    That is one of the reasons why I always run with "treat warnings as errors":

    Warning 1 Possible mistaken empty statement

    I can't run my code with that in there.

    Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

    S Offline
    S Offline
    Septimus Hedgehog
    wrote on last edited by
    #9

    Agreed. I'd love to use that option but that too has a sting in the tail. Unfortunately, he used more classes in the uber-project than I ever had classes at school and when I say it compiles with over 120 warnings, I'm not kidding. Some are easily rectifiable but there are others that are more sinister and which the compiler barfs about objects hiding those in the base class to name but one example. I'd love to select all the code and let Resharper reformat and correct it for me but I'm genuinely reluctant to do it. Some of the many 1000s of lines of code in a single file (yup, such files exist) contain 100s of Resharper suggestions to change and refactor. I really love Resharper, but I can't sleep easy knowing it might well clean the code too well that it breaks it. I don't subscribe to the "if it compiles clean, go live" paradigm but this project is one where it's best to let the proverbial canine sleep where it is. :zzz:

    1 Reply Last reply
    0
    • I Iain Clarke Warrior Programmer

      Braces do not protect you. Only a few weeks ago, I had:

      if (bSomeFlag);
      {
      SomeCodeWhichAlwayRan ();
      }

      I was tired! Iain.

      I am one of "those foreigners coming over here and stealing our jobs". Yay me!

      G Offline
      G Offline
      GParkings
      wrote on last edited by
      #10

      Similar tot he below issue, an example of which was posted on CP about a month ago

      if(some very long condition that pushes the right hand side of the statement off the screen) return;
      {

      //stuffs

      }

      It is likely the extra return was a temporary debugging thing that got left as a dingleberry ... but a subtle bug none-the-less. I personally always use braces and think it a shame that the above example compiles at all

      Pedis ex oris Quidquid latine dictum sit, altum sonatur

      1 Reply Last reply
      0
      • S Septimus Hedgehog

        I love them but, alas, the previous developer did not. There was a small, almost inconsequential "if" statement, not unlike: if(some_condition) do_some_action; At some point, the Nameless One, either through accident or lack of testing or malice, I know not which, changed it to: if(some_condition) ; do_some_action; Essentially, a null statement. I only discovered this when one of our test engineers mentioned that something he was testing seemed to give different results to what he was expecting. I eventually found the problem and thankfully, ReSharper's suggested change alerted me to it. I'm not saying that the use of braces protects you from all problems but I sure wish the previous chap had used them. I've long known the code is a mix of braces and no braces where "if"s are concerned but the inconsistency has long driven me nuts. Sadly, one came home to roost this morning. I'm sure it won't be the last.:mad: :((

        _ Offline
        _ Offline
        __yash__
        wrote on last edited by
        #11

        You got crooked teeth or something? :-D

        1 Reply Last reply
        0
        • D Dave Calkins

          correct. the braces don't protect you from the situation that was reported. what they do protect you from is someone later adding another statement inside there and forgetting to add the braces at that time.

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #12

          There is no protection from stupid.


          Failure is not an option; it's the default selection.

          1 Reply Last reply
          0
          • I Iain Clarke Warrior Programmer

            Braces do not protect you. Only a few weeks ago, I had:

            if (bSomeFlag);
            {
            SomeCodeWhichAlwayRan ();
            }

            I was tired! Iain.

            I am one of "those foreigners coming over here and stealing our jobs". Yay me!

            S Offline
            S Offline
            SinghUlarity
            wrote on last edited by
            #13

            Wouldn't that then make a case for starting braces next to the very first statement?

            if (xxx){

            Of course some would argue that makes the start and end brace difficult to spot :-D

            I are n00b.

            1 Reply Last reply
            0
            • S Septimus Hedgehog

              I love them but, alas, the previous developer did not. There was a small, almost inconsequential "if" statement, not unlike: if(some_condition) do_some_action; At some point, the Nameless One, either through accident or lack of testing or malice, I know not which, changed it to: if(some_condition) ; do_some_action; Essentially, a null statement. I only discovered this when one of our test engineers mentioned that something he was testing seemed to give different results to what he was expecting. I eventually found the problem and thankfully, ReSharper's suggested change alerted me to it. I'm not saying that the use of braces protects you from all problems but I sure wish the previous chap had used them. I've long known the code is a mix of braces and no braces where "if"s are concerned but the inconsistency has long driven me nuts. Sadly, one came home to roost this morning. I'm sure it won't be the last.:mad: :((

              G Offline
              G Offline
              Gregory Gadow
              wrote on last edited by
              #14

              Yeah, I've done that. I've learned -- the hard way, I will admit -- to ALWAYS use braces in C-derived code (C, C++, C# and Javascript.) They do not change the size or efficiency of compiled code and can be very helpful in tracking down bugs. I even go so far as to put all of my braces on their own line, with their own level of indentation: I can then print out the code, pull out a pencil and a ruler, and make sure everything lines up properly. For client-side script, I keep a working copy that's formatted and then compress it when it goes onto the server.

              1 Reply Last reply
              0
              • S Septimus Hedgehog

                I love them but, alas, the previous developer did not. There was a small, almost inconsequential "if" statement, not unlike: if(some_condition) do_some_action; At some point, the Nameless One, either through accident or lack of testing or malice, I know not which, changed it to: if(some_condition) ; do_some_action; Essentially, a null statement. I only discovered this when one of our test engineers mentioned that something he was testing seemed to give different results to what he was expecting. I eventually found the problem and thankfully, ReSharper's suggested change alerted me to it. I'm not saying that the use of braces protects you from all problems but I sure wish the previous chap had used them. I've long known the code is a mix of braces and no braces where "if"s are concerned but the inconsistency has long driven me nuts. Sadly, one came home to roost this morning. I'm sure it won't be the last.:mad: :((

                D Offline
                D Offline
                DeathByChocolate
                wrote on last edited by
                #15

                PHS241 wrote:

                I love them

                I prefer belts! ;P (Well someone had to say it! ;) )

                "State acheived after eating too many chocolate-covered coconut bars - bountiful" Chris C-B

                1 Reply Last reply
                0
                • S Septimus Hedgehog

                  I love them but, alas, the previous developer did not. There was a small, almost inconsequential "if" statement, not unlike: if(some_condition) do_some_action; At some point, the Nameless One, either through accident or lack of testing or malice, I know not which, changed it to: if(some_condition) ; do_some_action; Essentially, a null statement. I only discovered this when one of our test engineers mentioned that something he was testing seemed to give different results to what he was expecting. I eventually found the problem and thankfully, ReSharper's suggested change alerted me to it. I'm not saying that the use of braces protects you from all problems but I sure wish the previous chap had used them. I've long known the code is a mix of braces and no braces where "if"s are concerned but the inconsistency has long driven me nuts. Sadly, one came home to roost this morning. I'm sure it won't be the last.:mad: :((

                  M Offline
                  M Offline
                  Marc Clifton
                  wrote on last edited by
                  #16

                  PHS241 wrote:

                  I love them but, alas, the previous developer did not. There was a small, almost inconsequential "if" statement, not unlike:

                  I was convinced when my coworker recounted horror stories of adding a line in Fortran that was the equivalent of something like this:

                  if (fooIsTrue)
                  DoSomething();
                  DoSomethingMore();

                  Conversely, I once spend half a day debugging the equivalent of:

                  int i;
                  for (i=0; i<100; i++);
                  {
                  printf(i);
                  }

                  and wondering why the result was 100 (or more precisely, why the loop only executed once!) Marc

                  My Blog
                  The Relationship Oriented Programming IDE
                  Melody's Amazon Herb Site

                  1 Reply Last reply
                  0
                  • S Septimus Hedgehog

                    I love them but, alas, the previous developer did not. There was a small, almost inconsequential "if" statement, not unlike: if(some_condition) do_some_action; At some point, the Nameless One, either through accident or lack of testing or malice, I know not which, changed it to: if(some_condition) ; do_some_action; Essentially, a null statement. I only discovered this when one of our test engineers mentioned that something he was testing seemed to give different results to what he was expecting. I eventually found the problem and thankfully, ReSharper's suggested change alerted me to it. I'm not saying that the use of braces protects you from all problems but I sure wish the previous chap had used them. I've long known the code is a mix of braces and no braces where "if"s are concerned but the inconsistency has long driven me nuts. Sadly, one came home to roost this morning. I'm sure it won't be the last.:mad: :((

                    R Offline
                    R Offline
                    Roy from Detroit
                    wrote on last edited by
                    #17

                    I used to hate brackets. Every character you can eliminate from code is one less that can cause a bug. Then, like so many others, I wasted time debugging bugs like this: if(whatever) dosomething() dosomethingElse() Now where I work, we require brackets on everything, no matter what. It turns what could have been a 1-line IF into 4 lines, but if it avoids even one future bug, it is well worth it! BTW, the semicolon after the if, in VS2010 C# at least: if(whatever) ; { ... } Gives me a "Possible mistaken empty statement" warning when I build. Dang that thing is smart. Now if it would just fix it for me and not bother me with the warning at all...

                    1 Reply Last reply
                    0
                    • S Septimus Hedgehog

                      I love them but, alas, the previous developer did not. There was a small, almost inconsequential "if" statement, not unlike: if(some_condition) do_some_action; At some point, the Nameless One, either through accident or lack of testing or malice, I know not which, changed it to: if(some_condition) ; do_some_action; Essentially, a null statement. I only discovered this when one of our test engineers mentioned that something he was testing seemed to give different results to what he was expecting. I eventually found the problem and thankfully, ReSharper's suggested change alerted me to it. I'm not saying that the use of braces protects you from all problems but I sure wish the previous chap had used them. I've long known the code is a mix of braces and no braces where "if"s are concerned but the inconsistency has long driven me nuts. Sadly, one came home to roost this morning. I'm sure it won't be the last.:mad: :((

                      B Offline
                      B Offline
                      bVagadishnu
                      wrote on last edited by
                      #18

                      :) Don't need braces at all.

                      If [your condition here]
                      Your code here
                      End If

                      Schenectady? What am I doing in Schenectady?

                      1 Reply Last reply
                      0
                      • S Septimus Hedgehog

                        I love them but, alas, the previous developer did not. There was a small, almost inconsequential "if" statement, not unlike: if(some_condition) do_some_action; At some point, the Nameless One, either through accident or lack of testing or malice, I know not which, changed it to: if(some_condition) ; do_some_action; Essentially, a null statement. I only discovered this when one of our test engineers mentioned that something he was testing seemed to give different results to what he was expecting. I eventually found the problem and thankfully, ReSharper's suggested change alerted me to it. I'm not saying that the use of braces protects you from all problems but I sure wish the previous chap had used them. I've long known the code is a mix of braces and no braces where "if"s are concerned but the inconsistency has long driven me nuts. Sadly, one came home to roost this morning. I'm sure it won't be the last.:mad: :((

                        B Offline
                        B Offline
                        BobJanova
                        wrote on last edited by
                        #19

                        The braces aren't the problem here, the lack of a test framework is.

                        1 Reply Last reply
                        0
                        • S Septimus Hedgehog

                          I love them but, alas, the previous developer did not. There was a small, almost inconsequential "if" statement, not unlike: if(some_condition) do_some_action; At some point, the Nameless One, either through accident or lack of testing or malice, I know not which, changed it to: if(some_condition) ; do_some_action; Essentially, a null statement. I only discovered this when one of our test engineers mentioned that something he was testing seemed to give different results to what he was expecting. I eventually found the problem and thankfully, ReSharper's suggested change alerted me to it. I'm not saying that the use of braces protects you from all problems but I sure wish the previous chap had used them. I've long known the code is a mix of braces and no braces where "if"s are concerned but the inconsistency has long driven me nuts. Sadly, one came home to roost this morning. I'm sure it won't be the last.:mad: :((

                          B Offline
                          B Offline
                          Berthely
                          wrote on last edited by
                          #20

                          I like braces but some of my co-workers don't so I learn to live with that... X|

                          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