Click here to Skip to main content
15,884,472 members

Survey Results

When coding, do you put braces around single nested statements?

Survey period: 27 Aug 2018 to 3 Sep 2018

When coding using a language with braces, that is.

OptionVotes% 
Yes, always47536.48
Yes, mostly27120.81
Depends on the situation25019.20
Not usually16612.75
Never785.99
I don't code using a language with braces624.76



 
GeneralNot usually Pin
Leng Vang30-Aug-18 8:51
Leng Vang30-Aug-18 8:51 
GeneralYou people don't know how to be Analy Retentive Pin
Mycroft Holmes29-Aug-18 13:03
professionalMycroft Holmes29-Aug-18 13:03 
GeneralRe: You people don't know how to be Analy Retentive Pin
CodeWraith29-Aug-18 23:02
CodeWraith29-Aug-18 23:02 
GeneralI don't, the beautifier does, as it is supposed to Pin
Franc Morales28-Aug-18 23:58
Franc Morales28-Aug-18 23:58 
GeneralRe: I don't, the beautifier does, as it is supposed to Pin
CodeWraith29-Aug-18 23:05
CodeWraith29-Aug-18 23:05 
GeneralHow is "Yes, mostly" that different from "It depends on the situation"? Pin
TNCaver28-Aug-18 6:46
TNCaver28-Aug-18 6:46 
GeneralRe: How is "Yes, mostly" that different from "It depends on the situation"? Pin
Sammuel Miranda29-Aug-18 9:04
professionalSammuel Miranda29-Aug-18 9:04 
GeneralRe: How is "Yes, mostly" that different from "It depends on the situation"? Pin
Jared Stroebele30-Aug-18 3:42
professionalJared Stroebele30-Aug-18 3:42 
GeneralOne line-it every time i can Pin
Sammuel Miranda28-Aug-18 6:43
professionalSammuel Miranda28-Aug-18 6:43 
GeneralRe: One line-it every time i can PinPopular
Richard Deeming29-Aug-18 4:05
mveRichard Deeming29-Aug-18 4:05 
GeneralRe: One line-it every time i can Pin
Sammuel Miranda29-Aug-18 8:55
professionalSammuel Miranda29-Aug-18 8:55 
GeneralRe: One line-it every time i can Pin
Kevin McFarlane30-Aug-18 1:16
Kevin McFarlane30-Aug-18 1:16 
GeneralRe: One line-it every time i can Pin
Sammuel Miranda4-Sep-18 5:17
professionalSammuel Miranda4-Sep-18 5:17 
GeneralBraces don't always help Pin
Marc Clifton28-Aug-18 2:09
mvaMarc Clifton28-Aug-18 2:09 
GeneralRe: Braces don't always help Pin
den2k8828-Aug-18 3:00
professionalden2k8828-Aug-18 3:00 
GeneralRe: Braces don't always help PinPopular
Mladen Janković28-Aug-18 3:31
Mladen Janković28-Aug-18 3:31 
GeneralRe: Braces don't always help Pin
Ravi Bhavnani1-Sep-18 11:48
professionalRavi Bhavnani1-Sep-18 11:48 
GeneralRe: Braces don't always help Pin
Daniel Wilianto7-Sep-18 16:33
Daniel Wilianto7-Sep-18 16:33 
GeneralRe: Braces don't always help Pin
TNCaver28-Aug-18 6:41
TNCaver28-Aug-18 6:41 
GeneralRe: Braces don't always help Pin
Daniel Wilianto7-Sep-18 16:35
Daniel Wilianto7-Sep-18 16:35 
GeneralBrace == indent Pin
kalberts28-Aug-18 1:30
kalberts28-Aug-18 1:30 
I never make an indent of the following line(s) unless the line (i.e. last non-indented) ends in an opening brace.

If the single statement is short enough to fit on the same line as the enclosing statement, then there is no need for a brace.
for (int i = 0; i < 10; i++) SoundBeeper();
If it is too long (which is often the case, in particular if it is a function call with several parameters), I move it down to the next line, indent it, and end the first line with an opening brace,
for (int i = 0; i < maximumEntryCountInSet; i++) {
  AddAnotherEntryToTheSet(rawData[i], parent, formatstring: standadformat);
  }
In the old days, the hardcopy code printout days, the braced form was more common: The maximum line length was often set at 80. Nowadays, with 99.5% of all code reading done on a large, high resolution screen, code lines often extend to 100 columns, with room for the first form in more cases.

You must use common sense, though! If a statement really represents a large, complex operation (of the kind 'AddAnotherEnytryToTheSet'), it certainly deserves a line by itself, with the accompanying indent and braces. You omit the braces and newlines and indent only for obvious, simple, trivial statements like SoundBeeper(), break / return, simple assignments etc. In 90% of cases, such trivial statements fit well within 100 (or even 80) cols, while calls to complex functions with several parameters easily break that limit. So usually the formatting goes by itself.

What I never do is identing without braces, and an opening brace always either ends the line, or is matched by a closing brace that ends the same line.
GeneralRe: Brace == indent Pin
Kewin Rausch29-Aug-18 1:57
professionalKewin Rausch29-Aug-18 1:57 
GeneralRe: Brace == indent Pin
kalberts30-Aug-18 1:59
kalberts30-Aug-18 1:59 
GeneralRe: Brace == indent Pin
Kewin Rausch30-Aug-18 22:07
professionalKewin Rausch30-Aug-18 22:07 
GeneralRe: Brace == indent Pin
kalberts31-Aug-18 0:56
kalberts31-Aug-18 0:56 

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.