Skip to contentSkip to conversation

Style Issues / Concerns

OT James Kosin 2 participants 4 messages Mar 22, 2010

lore
Share & tools
lore
#0 lore raw

Everyone,

1) Please forgive me if this is the wrong forum to post this.

2) Please CC me when replying... I'm having list issues right now.

3) Questions / Concerns:

I'm a bit confused as to why there has been a style push to remove braces {} from the code.

Long ago, code was often missing these braces for exactly the point many patches are now coming back and reverting back to this antiquated style.

The problem was, and the reason the style changed to include these braces, was to prevent the common problem of forgetting the braces when adding another statement to the if or else block of the code.

Example:

if( (x != 0) )

    flag = true;
else
    flag = false;

----

if( (x != 0) )

    flag = true;
    call_something();
else
    flag = false;

----

Before everyone jumps in at once, this is a simple example that will produce a compiler error about the misplaced else. However if there are many if statements above this that may allow the else to be paired up with it then the code will compile and there will be a serious and very difficult bug in the code that will take days or months to find.

Why has the style for this changed back?
Does the compiler produce smaller code without the braces {}?

Just my 2-cents,
James Kosin

#1 lore raw
Quoted 6 lines · James Kosin

Before everyone jumps in at once, this is a simple example that will produce a compiler error about the misplaced else. However if there are many if statements above this that may allow the else to be paired up with it then the code will compile and there will be a serious and very difficult bug in the code that will take days or months to find.

Modern editors with auto indent mode makes it actually very easy to find such bugs.

Also checkpatch.pl checks for it now I believe.

Quoted 1 line

Does the compiler produce smaller code without the braces {}?

No, it's very arbitary.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
#2 lore raw
Quoted 8 lines · Andi Kleen
Quoted 6 lines · James Kosin

Before everyone jumps in at once, this is a simple example that will produce a compiler error about the misplaced else. However if there are many if statements above this that may allow the else to be paired up with it then the code will compile and there will be a serious and very difficult bug in the code that will take days or months to find.

Quoted 5 lines

Modern editors with auto indent mode makes it actually very easy to find such bugs.

Also checkpatch.pl checks for it now I believe.

Thanks for the speedy reply.

Does this mean developers need to install X or some graphical environment now to develop the kernel?
If so what options are available to those that don't want a graphical environment to develop under?

Sorry if I'm old fashioned.

Thanks again,
James K.

#3 lore raw
Quoted 12 lines · James Kosin
Quoted 11 lines · Andi Kleen
Quoted 6 lines · James Kosin

Before everyone jumps in at once, this is a simple example that will produce a compiler error about the misplaced else. However if there are many if statements above this that may allow the else to be paired up with it then the code will compile and there will be a serious and very difficult bug in the code that will take days or months to find.

Modern editors with auto indent mode makes it actually very easy to find such bugs.

Quoted 6 lines
Quoted 2 lines

Also checkpatch.pl checks for it now I believe.

Thanks for the speedy reply.

Does this mean developers need to install X or some graphical environment now to develop the kernel?

Modern was perhaps the wrong word. emacs, vim support that.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.