To brace, or not to brace

Pages: 12
So, first. Second is no braces but aligned as if there were braces.
I prefer the 2nd.

While it is indeed a trivial and easy fix, do you think it is trivial and easy to find the cause of a bug as a result of that? ;)

As long as I've been using it, I've never had to find a bug in my own code that was due to that. In other people's code, it has been trivial to find. The only time it wasn't obvious just from looking at the code that I can remember was when someone used style 3 and put more than one statement on the same line after an if.
Hence why I prefer the first one. I do find it quite interesting that people who have auto-indenting IDEs prefer the version that would require less typing in notepad. Is it actually a typing preference for when you don't use your normal IDE, or is it for aesthetic reasons?
Last edited on
I prefer the 2nd because I consider it easier to read. No extraneous junk, and things aren't too crammed together.
> for when you don't use your normal IDE
Damn muscle memory.
:w
I use the second. If braces are not needed why put them there? It also saves space.
Second for me too.

@ LB: I think you forgot this (also you should leave a space between if and paren):

1
2
3
4
5
if (stuffdota()) {
    stuffdotb();
} else {
    stuffdotc();
}


Edit: I just saw "ignore the placement of braces". Gee. Might as well ignore everything else as well, no?
Last edited on
closed account (z05DSL3A)
I prefer the first...not that that is worth anything.

Over the years I have found that it gives me less grief when modifying/maintaining code, I find it easier to visualise the structure of the code quickly without having to read it to much.
@Catfish3 I specifically indicated in the post to ignore brace placement.

Anyway, could you please explain the space between if and open paren? I've been trying to track this down for ages because I want to know why people do it.
That space between if and the opening parenthesis is part of the coding standards where I work. I hate it.

I do like to pad out anything inside the parentheses with spaces, though.
1
2
if( SomeFunc( someValue ) )
   // do stuff 
I guess it's just preference? It looks ugly to me, but I'm curious to know if there is a justified reason besides "it looks better to me" - if there is, I would take heed.
closed account (3qX21hU5)
Its part of the GNU Coding standards LB that is where it came from and why so many people use it.
The consistent treatment of blocks as statements (for the purpose of indentation) is a very distinctive feature of the GNU C code formatting style; as is the mandatory space before parentheses.
I know that it is from a standard, but what I don't know is the logic behind the decision - why is it done?
closed account (3qX21hU5)
There isn't any logic behind it really, it is just a style and looks better to some people. Not everything can be explained logically and I think this is one of them.
closed account (Dy7SLyTq)
i dont know for other people, but it was the style i was taught. like when im solving a rubiks cube, i start white side and idk why but it looks weird if i start red side. same for other bracket styles. it just looks weird to me cause i have that one style ingrained in me
I'm not very consistent when it comes to this. I try to be within one project, but between projects I change. Sometimes I do:

1
2
3
4
if(foo)
{
    bar;
}


And sometimes I do:

1
2
if(foo)
    bar;


or:

 
if(foo) bar;


Anything else is heresy and you should be burned at the stake. /kidding
Topic archived. No new replies allowed.
Pages: 12