if else standards...
-
I was just wondering how everyone does there if else statments. I was looking online and I see alot of this: if (condition) // Comment { } else if (condition) // Comment { } else // Comment { } or this: if (condition) { statements; } else if (condition) { statements; } else { statements; } I dont know why but I just found myself doing the following.... if(condition){ statements; }else{ if(condition){ statements; } } I dont know how or why I started doing that but dont ever remember doing it. I was just wondering what kind of styles people use. Here at work they dont really tell you what kind of style to use and I see it done in all different ways. Thanks :-D
There are 10 kinds of people in this world. Those who understand binary and those who don't. We shouldn't assume something's debugged just because everyone in the whole world has access to the source code.
The first one. Brackets on the same line are just asking for trouble (ie missed/mismatched brackets) if you ask me. Whitespace is free. cheers, Chris Maunder
-
The first one. Brackets on the same line are just asking for trouble (ie missed/mismatched brackets) if you ask me. Whitespace is free. cheers, Chris Maunder
Chris Maunder wrote: Whitespace is free. Screen estate isn't. :) Besides, now that VS.NET have caught up with early 90's [X]Emacs technology (matching brackets and smart indentation), mismatched crackets isn't that much of an issue as it was say 2 years ago. :) I am however missing the XEmacs feature "highlight expression". It highlights the expression under the cursor. So if the cursor is on the firs {, the editor would then change the background color on all text between the first { and the matching }. Now that's a killer feature, because it'll help you find mismatched stuff real easy. Why hasn't it been implemented I wonder? I doubt it's possible to hack it as a IDE script either, because I don't think it's possible to manipulate the color attributes of a specific text span. <desperate>Wasn't our friend Nick Hodapp a VS.NET manager kind of guy? Can you hear me Nick? Nick?! Nick!?!? I'm on me knees, begging you man! Please give me "highlight expression". Pretty please with sugar on top!</desperate> -- Oneigaishimasu! I blog too now[^]
-
I was just wondering how everyone does there if else statments. I was looking online and I see alot of this: if (condition) // Comment { } else if (condition) // Comment { } else // Comment { } or this: if (condition) { statements; } else if (condition) { statements; } else { statements; } I dont know why but I just found myself doing the following.... if(condition){ statements; }else{ if(condition){ statements; } } I dont know how or why I started doing that but dont ever remember doing it. I was just wondering what kind of styles people use. Here at work they dont really tell you what kind of style to use and I see it done in all different ways. Thanks :-D
There are 10 kinds of people in this world. Those who understand binary and those who don't. We shouldn't assume something's debugged just because everyone in the whole world has access to the source code.
I alweays use the first case.. one thign I hate it when people to this:
if (condition)
statement;
else if (condition)
statement;
else
statement;That just hacks me off...
George Carlin wrote: "Don't sweat the petty things, and don't pet the sweaty things." Jörgen Sigvardsson wrote: If the physicists find a universal theory describing the laws of universe, I'm sure the asshole constant will be an integral part of that theory.
My Blog[^]
-
I was just wondering how everyone does there if else statments. I was looking online and I see alot of this: if (condition) // Comment { } else if (condition) // Comment { } else // Comment { } or this: if (condition) { statements; } else if (condition) { statements; } else { statements; } I dont know why but I just found myself doing the following.... if(condition){ statements; }else{ if(condition){ statements; } } I dont know how or why I started doing that but dont ever remember doing it. I was just wondering what kind of styles people use. Here at work they dont really tell you what kind of style to use and I see it done in all different ways. Thanks :-D
There are 10 kinds of people in this world. Those who understand binary and those who don't. We shouldn't assume something's debugged just because everyone in the whole world has access to the source code.
-
I was just wondering how everyone does there if else statments. I was looking online and I see alot of this: if (condition) // Comment { } else if (condition) // Comment { } else // Comment { } or this: if (condition) { statements; } else if (condition) { statements; } else { statements; } I dont know why but I just found myself doing the following.... if(condition){ statements; }else{ if(condition){ statements; } } I dont know how or why I started doing that but dont ever remember doing it. I was just wondering what kind of styles people use. Here at work they dont really tell you what kind of style to use and I see it done in all different ways. Thanks :-D
There are 10 kinds of people in this world. Those who understand binary and those who don't. We shouldn't assume something's debugged just because everyone in the whole world has access to the source code.
Actually I am surprised you missed one:
if (condition) {
statements;
}
else if (condition) {
statements;
}
else {
statements;
}That's my personal preference. People who do the single line
if (condition)
statement
else if (...)
blah;should just be shot outright. it's such a pain to read and frequently debuggers won't show values correctly. Another pet peeve, as long as we are talking about single line nonsense is
class Foo {
public:
int getVal() {return val_;}
};Grrrr :mad: - what does it cost to put a line break in there!!! I know for a fact that VC6 will NOT allow you to properly inspect the val_ variable if you try and step into it, and won't let you do anything! But if it's written as
class Foo {
public:
int getVal() {
return val_;
}
};then everything is hunky-dory. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!
-
Chris Maunder wrote: Whitespace is free. Screen estate isn't. :) Besides, now that VS.NET have caught up with early 90's [X]Emacs technology (matching brackets and smart indentation), mismatched crackets isn't that much of an issue as it was say 2 years ago. :) I am however missing the XEmacs feature "highlight expression". It highlights the expression under the cursor. So if the cursor is on the firs {, the editor would then change the background color on all text between the first { and the matching }. Now that's a killer feature, because it'll help you find mismatched stuff real easy. Why hasn't it been implemented I wonder? I doubt it's possible to hack it as a IDE script either, because I don't think it's possible to manipulate the color attributes of a specific text span. <desperate>Wasn't our friend Nick Hodapp a VS.NET manager kind of guy? Can you hear me Nick? Nick?! Nick!?!? I'm on me knees, begging you man! Please give me "highlight expression". Pretty please with sugar on top!</desperate> -- Oneigaishimasu! I blog too now[^]
Jörgen Sigvardsson wrote: Chris Maunder wrote: Whitespace is free. Screen estate isn't. There is no way I'm letting you get away that argument. If you're still using a 1024 x 768 monitor then we'll start a New Monitor for Jörgen Fund :) Jörgen Sigvardsson wrote: Wasn't our friend Nick Hodapp a VS.NET manager kind of guy? He was (past tense) Product Manager (ie Marketing person) for Visual C++. He could only wail and gnash his teeth at the Program Manager to get new features implements. He's since headed to greener pastures. cheers, Chris Maunder
-
Chris Maunder wrote: Whitespace is free. Screen estate isn't. :) Besides, now that VS.NET have caught up with early 90's [X]Emacs technology (matching brackets and smart indentation), mismatched crackets isn't that much of an issue as it was say 2 years ago. :) I am however missing the XEmacs feature "highlight expression". It highlights the expression under the cursor. So if the cursor is on the firs {, the editor would then change the background color on all text between the first { and the matching }. Now that's a killer feature, because it'll help you find mismatched stuff real easy. Why hasn't it been implemented I wonder? I doubt it's possible to hack it as a IDE script either, because I don't think it's possible to manipulate the color attributes of a specific text span. <desperate>Wasn't our friend Nick Hodapp a VS.NET manager kind of guy? Can you hear me Nick? Nick?! Nick!?!? I'm on me knees, begging you man! Please give me "highlight expression". Pretty please with sugar on top!</desperate> -- Oneigaishimasu! I blog too now[^]
Jörgen Sigvardsson wrote: So if the cursor is on the firs {, the editor would then change the background color on all text between the first { and the matching } you can achieve something similar with ctrl+shift+]. it doesn't change the color, but selects the expresion. it works on VS6, and most likely on VS.NET, too. i know it's not the same as "highlight expression", but still it can help.
-
Jörgen Sigvardsson wrote: Chris Maunder wrote: Whitespace is free. Screen estate isn't. There is no way I'm letting you get away that argument. If you're still using a 1024 x 768 monitor then we'll start a New Monitor for Jörgen Fund :) Jörgen Sigvardsson wrote: Wasn't our friend Nick Hodapp a VS.NET manager kind of guy? He was (past tense) Product Manager (ie Marketing person) for Visual C++. He could only wail and gnash his teeth at the Program Manager to get new features implements. He's since headed to greener pastures. cheers, Chris Maunder
Chris Maunder wrote: Jörgen Sigvardsson wrote: Wasn't our friend Nick Hodapp a VS.NET manager kind of guy? He was (past tense) Product Manager (ie Marketing person) for Visual C++. He could only wail and gnash his teeth at the Program Manager to get new features implements. He's since headed to greener pastures. That would explain why his column has ground to a dead halt then. Any idea where he's moved on to? Anna :rose: Riverblade Ltd - Software Consultancy Services Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.
-
The first one. Brackets on the same line are just asking for trouble (ie missed/mismatched brackets) if you ask me. Whitespace is free. cheers, Chris Maunder
Definitely. Even with the aid of tools such as Visual Assist X the other styles are not something I care to come across. Anna :rose: Riverblade Ltd - Software Consultancy Services Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.
-
Jörgen Sigvardsson wrote: Chris Maunder wrote: Whitespace is free. Screen estate isn't. There is no way I'm letting you get away that argument. If you're still using a 1024 x 768 monitor then we'll start a New Monitor for Jörgen Fund :) Jörgen Sigvardsson wrote: Wasn't our friend Nick Hodapp a VS.NET manager kind of guy? He was (past tense) Product Manager (ie Marketing person) for Visual C++. He could only wail and gnash his teeth at the Program Manager to get new features implements. He's since headed to greener pastures. cheers, Chris Maunder
Chris Maunder wrote: . If you're still using a 1024 x 768 monitor then we'll start a New Monitor for Jörgen Fund I'd be happier if you'd start a "New Eyes for Jörgen Fund". Eventhough I'm using prescribed glasses, my eyesight isn't what it used to be. :) [edit]Meaning: I want to see as much code as possible on one page[edit] Chris Maunder wrote: He's since headed to greener pastures. Good for him :) -- Oneigaishimasu! I blog too now[^]
-
Jörgen Sigvardsson wrote: So if the cursor is on the firs {, the editor would then change the background color on all text between the first { and the matching } you can achieve something similar with ctrl+shift+]. it doesn't change the color, but selects the expresion. it works on VS6, and most likely on VS.NET, too. i know it's not the same as "highlight expression", but still it can help.
It's too manual and it's a bit too risky with a selection... And yeah, I forgot to mention that "highlight expression" works on (), [] and {}; I *think* it works on case/break too, but I'm unsure as it was quite some time ago I used XEmacs. -- Oneigaishimasu! I blog too now[^]
-
It's too manual and it's a bit too risky with a selection... And yeah, I forgot to mention that "highlight expression" works on (), [] and {}; I *think* it works on case/break too, but I'm unsure as it was quite some time ago I used XEmacs. -- Oneigaishimasu! I blog too now[^]
this works on (), [] and {} in VS, at least on my machine :) but i agree that it's too manual. maybe we should post a feature request for Visual Assist or Resharper?
-
Chris Maunder wrote: . If you're still using a 1024 x 768 monitor then we'll start a New Monitor for Jörgen Fund I'd be happier if you'd start a "New Eyes for Jörgen Fund". Eventhough I'm using prescribed glasses, my eyesight isn't what it used to be. :) [edit]Meaning: I want to see as much code as possible on one page[edit] Chris Maunder wrote: He's since headed to greener pastures. Good for him :) -- Oneigaishimasu! I blog too now[^]
Well if you're going to get new eyes then I want some too... I'd settle for the LASIK or LASEK surgery though ;-) Regards, Brian Dela :-) Now Bloging![^]
-
The first one. Brackets on the same line are just asking for trouble (ie missed/mismatched brackets) if you ask me. Whitespace is free. cheers, Chris Maunder
It is funny you mention that, because some of the most OBSCURE programming errors we have encountered here are because someone puts the opening brace on the next line, and a maintenance guy comes along and puts a statement BETWEEN the if line and the opening brace! this: if( x ) { } else { } gets converted into if( x ) y; { }else { } Now that REALLY jacks up your code!
-
It is funny you mention that, because some of the most OBSCURE programming errors we have encountered here are because someone puts the opening brace on the next line, and a maintenance guy comes along and puts a statement BETWEEN the if line and the opening brace! this: if( x ) { } else { } gets converted into if( x ) y; { }else { } Now that REALLY jacks up your code!
This is the first legitimate reason I've seen for not using the first form ... ... but, I'm still sticking to first format anyhow.
-
This is the first legitimate reason I've seen for not using the first form ... ... but, I'm still sticking to first format anyhow.
In about 20 years of coding C that is the ONLY reason I have been able to accept for not using the first form. Recently, I find it easier to accept because the IDE will match braces for me anyway. Along similar lines, do people prefer this: if( x ) { } or this if ( x ) { } of the one I like: if( x ){ } For some reason my 'processor' is happier if the parenthesis is more closely grouped with the control statement or its close expression than not. I like this: if( x && (y == 1) ){ more than if ( x && ( y == 1 ) ) { for example.