Do you use brackets?

AFB

Lifer
Jan 10, 2004
10,718
3
0
eg.,

while(true)
{
}

Things like

if()
x();
else if ()
if()
f()
else()
.....

 

notfred

Lifer
Feb 12, 2001
38,241
4
0
If they're required. I don't usually use them for one-line blocks.
if(condition)
{
somefunction()
}
else
{
otherfunction()
}

Just seems to waste so much damn space.
 

juiio

Golden Member
Feb 28, 2000
1,433
4
81
If you're writing code professionally, you should always use them, even for single-line blocks. It is more readable and will cut down on future mistakes.

I prefer put the open brace on the same line as the if/while/else/etc though to cut down on space used.

if( blah == 1 ){
burp();
}
 

znaps

Senior member
Jan 15, 2004
414
0
0
I'm with juiio. Always use them on the same line, even if it's a one-liner.
 

ArmchairAthlete

Diamond Member
Dec 3, 2002
3,763
0
0
Not in Python =)

But most of the time I don't skip them even for one-liners in Java. With NetBeans I only have to type one of 'em most of the time, the stuff's all indented right too. If not, highlight a bunch of stuff and press CTRL + SHIFT + F.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: ArmchairAthlete
Not in Python =)
I added the last line for you ;):p
But most of the time I don't skip them even for one-liners in Java. With NetBeans I only have to type one of 'em most of the time, the stuff's all indented right too. If not, highlight a bunch of stuff and press CTRL + SHIFT + F.

Wow, that's pretty cool.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
If I don't the code formatter does it for me so there isn't much choice.
At any rate, all I have to do it type:
if (condition) { <return>

and this is automatically generated:

if (condition) {
...|
}

where the pipe is the location of the cursor so it's not actually much extra typing.

Edit: I think you should add some more options to the second poll. I can live with one liners but if you put the statement on a second line and indent it then I'd much rather see some brackets.
 

clamum

Lifer
Feb 13, 2003
26,256
406
126
For one-line statements? No, although I indent the statement. I don't think it's hard to read if it's indented.
 

Schrodinger

Golden Member
Nov 4, 2004
1,274
0
0
Sometimes I'm of the thought that "this could grow, and it would be less likely to create a problem if you just toss braces around it. Late at night with little to no sleep, I can and do make such stupid mistakes once in a while. Then again, I shouldn't be coding that late anyhow.

What I really dislike is the one liners
eg if (something) blah();

I'd much rather see
if (something)
blah();

Don't know why. Just preference for one reason or another.
 

BFG10K

Lifer
Aug 14, 2000
22,709
3,003
126
I always write as little code as possible so I only use them when it's absolutely necessary. I'd much rather indent or better yet, leave it on the same line. Vertical screen estate is precious, especially when scolling through pages and pages of code.

 

Spydermag68

Platinum Member
Apr 5, 2002
2,616
99
91
I had to track down a bug once and came across code something like this

if foo if bar x=something;

The problem was foo and bar were not boolean values.