Click here to Skip to main content
15,849,996 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Hello world again Pin
pompey-boy27-Feb-23 15:22
pompey-boy27-Feb-23 15:22 
GeneralRe: Hello world again Pin
Rage12-Dec-22 22:21
professionalRage12-Dec-22 22:21 
GeneralCurly braces Pin
pkfox12-Dec-22 0:32
professionalpkfox12-Dec-22 0:32 
GeneralRe: Curly braces PinPopular
Jacquers12-Dec-22 0:37
Jacquers12-Dec-22 0:37 
GeneralRe: Curly braces Pin
honey the codewitch12-Dec-22 3:46
mvahoney the codewitch12-Dec-22 3:46 
GeneralRe: Curly braces Pin
fgs196312-Dec-22 4:22
fgs196312-Dec-22 4:22 
GeneralRe: Curly braces Pin
Jacquers12-Dec-22 4:37
Jacquers12-Dec-22 4:37 
GeneralRe: Curly braces Pin
trønderen12-Dec-22 5:30
trønderen12-Dec-22 5:30 
Jacquers wrote:
I generally just use what's in the specific language's style guide.
For C/C++ there is about 42 different bracing / indentation styles fighting for dominance, so referring to "the specific language's" style, as if it was unambiguous, is meaningless.

From a logical point, I would prefer
void AFunc() {
   }
but I have never seen that promoted in any style guide.

The opening brace comes when the statement cannot be completed on the current line, indicating that a block is to follow. You should before you leave the line that you won't find a single one-statement line, but a block. I am one who think "if (day==sunday) weekend = true;" in one line is perfectly fine. "if (day==sunday) {" shows that the statement is not complete.

The following block is indented. An indentation always follows a brace. No an indentation without an opening brace; no opening brace without an indentation.
"if (day==sunday)
   {
   }
starts the indentation before the brace - that is inconsistent!
Undenting follows a closing brace. No undentation without a closing brace, no closing brace without an undentation.
"if (day==sunday)
{
   // indented code block
}
undents before reaching the closing brace - that is inconsistent.

Noone seems to agree with my logic. So I bow my head and follow whatever style guide is enforced upon me.

Switch statements mess up indentation in C/C++. One common layout is:
switch (day) {
   case (day == saturday):
   case (day == sunday):
      celebrate();
      break;
   default:
      gotowork();
      break;
   }
The case alternatives are not blocks, so they don't need braces (that is also why they need the 'break'!), but they are indented! I certainly wish they were blocks, for consistency's sake (and I really dislike the 'default is fall through'), so I prefer to make them blocks, adding braces, to justify the indentation. Very few agree with this logic, too - they are so used to seeing indents without any braces justifying it that the inconsistency doesn't bother them.
GeneralRe: Curly braces Pin
honey the codewitch12-Dec-22 6:40
mvahoney the codewitch12-Dec-22 6:40 
GeneralRe: Curly braces Pin
trønderen12-Dec-22 7:37
trønderen12-Dec-22 7:37 
GeneralRe: Curly braces Pin
honey the codewitch12-Dec-22 7:42
mvahoney the codewitch12-Dec-22 7:42 
GeneralRe: Curly braces Pin
OriginalGriff12-Dec-22 0:57
mveOriginalGriff12-Dec-22 0:57 
GeneralRe: Curly braces Pin
pkfox12-Dec-22 1:20
professionalpkfox12-Dec-22 1:20 
GeneralRe: Curly braces Pin
OriginalGriff12-Dec-22 1:30
mveOriginalGriff12-Dec-22 1:30 
GeneralRe: Curly braces Pin
Jörgen Andersson12-Dec-22 4:00
professionalJörgen Andersson12-Dec-22 4:00 
GeneralRe: Curly braces Pin
CPallini12-Dec-22 2:03
mveCPallini12-Dec-22 2:03 
GeneralRe: Curly braces Pin
Slacker00712-Dec-22 2:33
professionalSlacker00712-Dec-22 2:33 
GeneralRe: Curly braces Pin
Mike Hankey12-Dec-22 3:01
mveMike Hankey12-Dec-22 3:01 
GeneralRe: Curly braces Pin
Richard MacCutchan12-Dec-22 3:07
mveRichard MacCutchan12-Dec-22 3:07 
GeneralRe: Curly braces Pin
OriginalGriff12-Dec-22 3:24
mveOriginalGriff12-Dec-22 3:24 
GeneralRe: Curly braces Pin
Ron Anders12-Dec-22 3:27
Ron Anders12-Dec-22 3:27 
GeneralRe: Curly braces Pin
Mircea Neacsu12-Dec-22 3:35
Mircea Neacsu12-Dec-22 3:35 
GeneralRe: Curly braces Pin
MarkTJohnson12-Dec-22 4:48
professionalMarkTJohnson12-Dec-22 4:48 
GeneralRe: Curly braces Pin
Mircea Neacsu12-Dec-22 5:13
Mircea Neacsu12-Dec-22 5:13 
GeneralRe: Curly braces Pin
den2k8812-Dec-22 5:37
professionalden2k8812-Dec-22 5:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.