Click here to Skip to main content
15,867,453 members

Survey Results

Braces around single line commands. Needed or not?

Survey period: 12 Feb 2018 to 19 Feb 2018

It's just about the braces. Not about whether the leading brace should or should not be on the same line as the conditional. One war at a time.

OptionVotes% 
I prefer

if (condition)
  statement;
21323.20
I prefer

if (condition)
{
  statement;
}
54158.93
It depends16417.86



 
GeneralRe: OK, so I'm a pedant, but really... Pin
PIEBALDconsult12-Feb-18 2:40
mvePIEBALDconsult12-Feb-18 2:40 
GeneralRe: OK, so I'm a pedant, but really... Pin
ZurdoDev12-Feb-18 2:55
professionalZurdoDev12-Feb-18 2:55 
GeneralRe: OK, so I'm a pedant, but really... Pin
ZurdoDev12-Feb-18 2:56
professionalZurdoDev12-Feb-18 2:56 
GeneralI prefer the missing option Pin
KarstenK11-Feb-18 20:22
mveKarstenK11-Feb-18 20:22 
GeneralRe: I prefer the missing option Pin
den2k8811-Feb-18 22:31
professionalden2k8811-Feb-18 22:31 
GeneralRe: I prefer the missing option Pin
W Balboos, GHB12-Feb-18 0:25
W Balboos, GHB12-Feb-18 0:25 
GeneralRe: I prefer the missing option Pin
CodeWraith13-Feb-18 2:04
CodeWraith13-Feb-18 2:04 
GeneralI prefer the middle solution, but ... Pin
OriginalGriff11-Feb-18 20:01
mveOriginalGriff11-Feb-18 20:01 
... indented properly Mad | :mad:

C#
if (condition)
    {
    statement;
    }

There are occasions when this is OK
C#
if (condition) statement;
But only when statement is short and obvious.

Anything longer than a dozen characters or so needs a new line, and braces. Modern IDE's handle the indentation for you, but they still get it wrong and it's easy to read
C#
if (condition)
   statement;
   statement;
wrongly, especially if you use the excreble 1TB indentation style
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!


modified 12-Feb-18 4:06am.

GeneralI always go ... Pin
Mehdi Gholam11-Feb-18 19:14
Mehdi Gholam11-Feb-18 19:14 
GeneralThis case is also applied to WHILE and FOR ....! Pin
koolprasad200311-Feb-18 18:21
professionalkoolprasad200311-Feb-18 18:21 
GeneralThose are BRACEs, not BRACKETs Pin
PIEBALDconsult11-Feb-18 18:11
mvePIEBALDconsult11-Feb-18 18:11 
GeneralRe: Those are BRACEs, not BRACKETs Pin
effayqueue12-Feb-18 4:30
effayqueue12-Feb-18 4:30 
GeneralRe: Those are BRACEs, not BRACKETs Pin
Marc Clifton12-Feb-18 8:41
mvaMarc Clifton12-Feb-18 8:41 

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.