Click here to Skip to main content
15,884,926 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 Pin
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 
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 
Sure, and in programming, they may be manadatory e.g. for delimiting a group of statements to be repeated.

But although it is permitted, in math, to write (3 + 5) = 8, but people would ask why you use them. You don't use them unless you want to override a general rule, such as multiplication / division before addition / subtraction. Or in expressions so complex that humans find it difficult to interpret them even if general rules are followed, so you add parentheses for clarification. But those are very rare cases; 99.99% of all real-life math expressions are so simple that the general rules for asocciation is sufficient, and no conceptually superfluous delimiters are used. You won't fail an exam in any school anywhere in the world because you write '3 + 5 = 8' rather than '(3 + 5) = 8'!

Programming in Pascal (and most other pre-C languages) you may of course use paretheses to override general rules such as operator precedence, but for a simple expression such as "if a + b = 8 ..." you don't need it. And the compiler won't barf if you omit parentheses.

The thing with C is that you must write "if (a + b == 8) ...", not to override precedence, not to improve readability by grouping terms, but because the parser is incapable of understanding it unless you give it a helping hand. The computer will barf if you omit them. That is a completely different reason, having nothing to do with the math side of it, nor with human comprehension. It is purely there for the compiler.

Statements in a programming language must be unambiguous; natural language is not. But programming languages other than C have certainly proven that a conditional statement can be unambiguous without enclosing the condition in parentheses.

I read one study, I believe it was done by a British university, where a number of test persons (all programmers) where given a program source code printout, and given a fixed time to study it, before answering a number of questions about the program. The program was the same for all test persons, but one group got it formatted in the spacious programming style, with e.g. 'if', if-clause, 'else', else-clause and maybe (I don't remember) braces each occupying a line. Other groups got the exact same code laid out to resemble "natural text", like 'if (itsRaining) UseUmbrella();' in one line. The study went though a number of programs and layout options.

The conclusion for this study was that the more the program layout resembled "natural text", the better was the comprehension of the program after a fairly short study. Those who read the natural text layout could answer more questions about the program functions, its structure etc. than those reading the loose programming style layout (which probably made the printout three times as many lines/pages). So some aspects of natural text were proven to be valuable, even without making a single change to the source code, only in its whitespace.

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.