Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

djberg96 (2603)

djberg96
  (email not shown publicly)

Journal of djberg96 (2603)

Thursday November 11, 2004
12:17 PM

C coding style change

[ #21810 ]
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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Don't bring that code my way!
    • 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.

      • 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.
  • 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?