Semicolon at the end of a comment line.
-
For some reason - maybe it's my editor? - but lately I've been dropping a lot of
{
open braces afterif
(K&R style for me in C/C++) and it rains absolute mayhem down on my source code. My editor lights up like a $5 {expletive, use your imagination}, and of course nothing compiles. It's also just the sort of thing your brain will fill in for you automatically if it's not there while scanning code. Thanks brain!To err is human. Fortune favors the monsters.
Yeah, with K&R your brain will register the harmful semicolon. But I for instance always use Allman style with any language.
Advertise here – minimum three posts per day are guaranteed.
-
Their cod wasn't working? That sounds fishy to me.
Edit: got it (the fishy part) :) Here, let me clear the picture:
if(obj->nVar > 0);
{
//unreachable code
//more unreachable code
//even more unreachable code
}It was verry confusing because it was CLI manageable section and without a special pragma you cannot debug this code.
Advertise here – minimum three posts per day are guaranteed.
-
Yeah, with K&R your brain will register the harmful semicolon. But I for instance always use Allman style with any language.
Advertise here – minimum three posts per day are guaranteed.
Single Step Debugger wrote:
always use Allman style with any language.
If you can: GO forces you to use K&R style. Allman is a syntax error :wtf:
Mircea
-
Better than a semicolon at the end of an "if" statement. :sigh: took me a half day to realize why my coworker's code is not working.
Advertise here – minimum three posts per day are guaranteed.
Beware of coworkers with a malfunctioning cod piece!
-
Beware of coworkers with a malfunctioning cod piece!
Mind bleach, I need mind bleach!!! X|
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
-
Their cod wasn't working? That sounds fishy to me.
Pete O'Hanlon wrote:
heir cod wasn't working? That sounds fishy to me.
Beware of people with a non functional cod piece.
-
Pete O'Hanlon wrote:
heir cod wasn't working? That sounds fishy to me.
Beware of people with a non functional cod piece.
Mind bleach, I need mind bleach!!! X|
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
-
For some reason - maybe it's my editor? - but lately I've been dropping a lot of
{
open braces afterif
(K&R style for me in C/C++) and it rains absolute mayhem down on my source code. My editor lights up like a $5 {expletive, use your imagination}, and of course nothing compiles. It's also just the sort of thing your brain will fill in for you automatically if it's not there while scanning code. Thanks brain!To err is human. Fortune favors the monsters.
I always use braces, even when not required. It future proofs for later maintenance. There was a great article supporting the always use braces approach, but I can’t remember the exact format used. The article had extensive test cases around merging changes from multiple branches and showed how braces protected correct merging. I have tried googling it, but with no luck. I guess I could just Chat GPT to provide the answer now? And if I do not like the answer then I will ask Chat GPT to write a white paper proving that my preferred brace style is superior and force my team to adopt it.
-
I always use braces, even when not required. It future proofs for later maintenance. There was a great article supporting the always use braces approach, but I can’t remember the exact format used. The article had extensive test cases around merging changes from multiple branches and showed how braces protected correct merging. I have tried googling it, but with no luck. I guess I could just Chat GPT to provide the answer now? And if I do not like the answer then I will ask Chat GPT to write a white paper proving that my preferred brace style is superior and force my team to adopt it.
I *was* using braces. I'm talking about typing:
if(foo!=nullptr)
printf("foo valid\n");
}Like that.
To err is human. Fortune favors the monsters.
-
I *was* using braces. I'm talking about typing:
if(foo!=nullptr)
printf("foo valid\n");
}Like that.
To err is human. Fortune favors the monsters.
At least it is a syntax error. That is a scenario where you can ask the editor to re-format for you and then compare with pre-format to see what shifted/indented unexpectedly. Like you said, the indentation will trick you into not noticing the missing {. The one that bit me was if () // do foo foo(); and I added prefoo(); ahead of foo(); without adding braces. “It was a setup, I tell you, wiseguy”
-
At least it is a syntax error. That is a scenario where you can ask the editor to re-format for you and then compare with pre-format to see what shifted/indented unexpectedly. Like you said, the indentation will trick you into not noticing the missing {. The one that bit me was if () // do foo foo(); and I added prefoo(); ahead of foo(); without adding braces. “It was a setup, I tell you, wiseguy”
This is why I *always* use braces after an if is there is only one line of code ...
if(expression == true) {
doSomething();
}Then later when reviewing my code, I decide to tidy it up because it looks nicer ...
if(expression == true) doSomething();
Third time around I add one line of code and spend the rest of the day trying to figure out why nothing works.
Nothing succeeds like a budgie without teeth. To err is human, to arr is pirate.
-
At least it is a syntax error. That is a scenario where you can ask the editor to re-format for you and then compare with pre-format to see what shifted/indented unexpectedly. Like you said, the indentation will trick you into not noticing the missing {. The one that bit me was if () // do foo foo(); and I added prefoo(); ahead of foo(); without adding braces. “It was a setup, I tell you, wiseguy”
Yeah, that's not a fun bug. Fortunately for me, the number of times that has happened to me I can count on one hand.
To err is human. Fortune favors the monsters.
-
I *was* using braces. I'm talking about typing:
if(foo!=nullptr)
printf("foo valid\n");
}Like that.
To err is human. Fortune favors the monsters.
-
Too late, already pressed F5, Someday I or someone will get a mild chuckle.
-
Better than a semicolon at the end of an "if" statement. :sigh: took me a half day to realize why my coworker's code is not working.
Advertise here – minimum three posts per day are guaranteed.
That is a perfectly valid SAS code[^]. I still don't believe in it when I see it.
-
Edit: got it (the fishy part) :) Here, let me clear the picture:
if(obj->nVar > 0);
{
//unreachable code
//more unreachable code
//even more unreachable code
}It was verry confusing because it was CLI manageable section and without a special pragma you cannot debug this code.
Advertise here – minimum three posts per day are guaranteed.
um... Not only would that ode be reachable, it would be executed every time.
Truth, James
-
um... Not only would that ode be reachable, it would be executed every time.
Truth, James
Yes, exactly - bad wording on my side.
Advertise here – minimum three posts per day are guaranteed.
-
Better than a semicolon at the end of an "if" statement. :sigh: took me a half day to realize why my coworker's code is not working.
Advertise here – minimum three posts per day are guaranteed.
Single Step Debugger wrote:
Better than a semicolon at the end of an "if" statement.
That's a fun one. Back in my college days, a fellow student (much older than the rest of us, I think he decided to go back to college in his 40s) had the habit of leaving his system logged in, with his editor running...so whenever he took a break to (typically) go pick something up at the cafeteria, we'd do things like adding a bunch of spaces after a for loop and then a semi-colon (so it's off-screen and not visible), so his code read:
for ( int i = 0; i < someLimit; i++ ) ; <-- not visible without scrolling horizontally
{
// this only ran once no matter what
}We did it many times, but he never learned to lock his workstation...fool me once... Poor guy. He was already struggling, and we made him waste a lot of his time on things like this... Gaetan, wherever you are, I hope you still had a successful and rewarding career... :rose:
-
Single Step Debugger wrote:
Better than a semicolon at the end of an "if" statement.
That's a fun one. Back in my college days, a fellow student (much older than the rest of us, I think he decided to go back to college in his 40s) had the habit of leaving his system logged in, with his editor running...so whenever he took a break to (typically) go pick something up at the cafeteria, we'd do things like adding a bunch of spaces after a for loop and then a semi-colon (so it's off-screen and not visible), so his code read:
for ( int i = 0; i < someLimit; i++ ) ; <-- not visible without scrolling horizontally
{
// this only ran once no matter what
}We did it many times, but he never learned to lock his workstation...fool me once... Poor guy. He was already struggling, and we made him waste a lot of his time on things like this... Gaetan, wherever you are, I hope you still had a successful and rewarding career... :rose:
That's so evil! I like it! :-D
Advertise here – minimum three posts per day are guaranteed.
-
Better than a semicolon at the end of an "if" statement. :sigh: took me a half day to realize why my coworker's code is not working.
Advertise here – minimum three posts per day are guaranteed.