Indentation without brackets?

mugs

Lifer
Apr 29, 2003
48,920
46
91
nice descriptive poll... I don't use brackets on single line ifs... sometimes I make it all one line, sometimes I make it two lines, depending on the context.

For example, in PHP I have a wrapper function for mysql_query() that stores every query I run, any MySQL errors they generate, and their execution times in a global variable. If I have a problem with a page, I output those variables at the end of the page to try to figure it out. So every time I have a mysql query, I'd use something like:

if($debug==1) mysql_query_debug($sql); else mysql_query($sql);
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: mugs
nice descriptive poll... I don't use brackets on single line ifs... sometimes I make it all one line, sometimes I make it two lines, depending on the context.

For example, in PHP I have a wrapper function for mysql_query() that stores every query I run, any MySQL errors they generate, and their execution times in a global variable. If I have a problem with a page, I output those variables at the end of the page to try to figure it out. So every time I have a mysql query, I'd use something like:

if($debug==1) mysql_query_debug($sql); else mysql_query($sql);

Makes sense
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Omitting brackets (or equivalent block delimiters) is convenient for one line ifs and such but it's a bad idea when you're developing in a group. The only time I'll allow myself to omit them is for real short if statements, like a single identifier boolean condition and a short execution statement. Even then, I feel bad doing it.

Sometimes compact expressions improve code readability but readability is kind of subjective, especially when you're talking about the person writing the code. I always try to remember that not everyone reads code the same way and the only completely standard, unambiguous way is to use the brackets.
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
I try my best to use brackets even when it's just one-liners..

Such as the above code snippet, i'd write it as:

if ($debug==1) { mysql_query_debug($sql); }
else { mysql_query($sql); }

sometimes i even went as far as making the opening { on the if and else statement line up.
but then again, i like my code "pretty" ,)

exceptions would be when i'm about to meet my deadline, or if it's a project where the requirements keep changing and i don't feel like finishing it anymore

actually, now that i think about it ...
is this thread about indentation or bracketing? o.o?