Braces.
-
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: :((
-
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.
There is no protection from stupid.
Failure is not an option; it's the default selection.
-
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!
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.
-
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: :((
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.
-
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: :((
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
-
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: :((
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 -
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: :((
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...
-
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: :((
:) Don't need braces at all.
If [your condition here]
Your code here
End IfSchenectady? What am I doing in Schenectady?
-
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: :((
-
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: :((