C coding style change

djberg96 on 2004-11-11T17:17:06

In the past, including the very recent past, I have always used brackets for my C "if-else" conditions, even if there was only a single line within the if clause. if(some_condition){ printf("Whatever\n"); } I guess it was just a combination of paranoia, preference, and anticipation of adding additional code within the if condition that led me to code this way.

I've had a change of heart. This morning. At 10:12 am to be precise. Suddenly, it just started to annoy the crap out of me. I realize I have to pay a little extra attention to detail by omitting the brackets, but I suddenly like the 'no-bracket' style better. if(some_condition) printf("Whatever\n");

/me shrugs


ICKY POO POO

zatoichi on 2004-11-11T18:34:16

Don't bring that code my way!

Re:ICKY POO POO

djberg96 on 2004-11-11T18:57:08

Heh. Well, the functions where I'm doing this are generally short. For larger functions I'd probably be more inclined to keep the brackets.

The main problem I have with people using this style is that they don't indent or space worth a darn. That can get real confusing, real quick. That's probably another reason I've avoided it in the past.

Re:ICKY POO POO

spur on 2004-11-12T07:36:42

Just because a feature can be misused - doesn't mean it should be misused (we Perl hackers know it best of all...). The "no bracket" single statement "if" is in C for a reason - and AFAIK it is considered good style to use it. With proper indentation, the problems you may run into become blazingly obvious. In 6 years of C experience, I've never had a bug resulting from this feature.

Confounded by tabs

dws on 2004-11-12T17:11:21

Some day you'll be skimming code that's passed through the fingers of someone who had their tabs set to an unusual number of spaces, and something like

    if (somecondition)
        printf("Whatever\n");
        dosomethingelse();
will go flying by. Are you sure you'll read it correctly?

Re:Confounded by tabs

djberg96 on 2004-11-12T21:56:45

I have learned to always set the "tabs to spaces" option in whatever editor I'm using. :)