The ideal brace alignment

Published June 24, 2007
Advertisement
I was recently browsing some source code to some open-source projects, and I noticed that most of the developers prefer different brace alignments and use them quite consistently, but I've always wondered why THAT brace alignment why not THIS one?

The following are the three most common brace alignments that I see :

if ( condition ) {    ...}if ( condition ){    ...}if ( condition )   {   ...   }


Personally I prefer the second, mainly because after many levels of comparisons you can see exactly where you are because the braces line up. I know the first brace alignment is the Java 'standard', but I really see no reason why I'm supposed to use that one - In fact, I think that one and the last brace alignment example are nearly unhelpful.

Why would you want to put the curly brace on the same line as your comparison? Does it help you in any way? I don't see how.

As for the last alignment example, I just think it's plain ugly.

So, what brace alignment do YOU use and why?
Previous Entry O_O A month already?
Next Entry *sigh*
0 likes 10 comments

Comments

Stompy9999
I use the second one, and I can't stand the first or third one. The XNA Game Studio Express always has the starting code with the first one, so I always take a few minutes to put the braces the way I like them.

The second one is the only one that seems logical and easy to follow, so that's why I use it.
June 24, 2007 09:30 PM
Trapper Zoid
I also use the second one so I can have the brackets aligned. But I'm fairly happy with using the first case if need be; the main argument in favour of that style is it saves space, allowing you to view more code on the screen at once. Personally I like lots of space, but that's just me.

The third style is just plain weird.
June 24, 2007 09:44 PM
Ravuya
First, because that's how K&R did it. This "brace on new line" crap is just wasting whitespace. [wink]
June 24, 2007 09:45 PM
Sir Sapo
#2 for me
June 24, 2007 10:36 PM
LachlanL
#2 for me too. It just makes sense. [wink]
June 24, 2007 11:00 PM
Drilian
#2. "Wasting whitespace" was a problem back when monitors had 24 lines of text, but on today's ginormodisplays, it's more useful for me to have the braces line up in an easy-to-see manner. Also, I sort of like the way there's a bit of a "Break" created by having the brace on its own line. It helps the code "breathe" a bit.
June 24, 2007 11:56 PM
Swattkidd
i use the 2nd one because it just makes it easier to see. Sometimes for the first one you cant tell if its there or not at quick glance. and i use Java.
June 25, 2007 04:09 AM
choffstein
#1
June 25, 2007 06:51 PM
bladerunner627
Quote:Original post by Drilian
#2. "Wasting whitespace" was a problem back when monitors had 24 lines of text, but on today's ginormodisplays, it's more useful for me to have the braces line up in an easy-to-see manner. Also, I sort of like the way there's a bit of a "Break" created by having the brace on its own line. It helps the code "breathe" a bit.


Yea, I tend to space my code out quite a bit aswell, I don't think it's a bad habit, it makes it easier to see where the larger sections lie.
June 26, 2007 06:02 PM
Hushed
Second one. Its easier to read.
July 03, 2007 02:13 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

Boo!

1570 views

Group blog

1060 views

Easy Usage

1077 views

Angel Script

938 views

My game idea

955 views

Lightmaps

929 views

Yay BSPs!

928 views
Advertisement