Which style do programmers use more often?
Style #1:
Style #2:Code:if(1) {
/* code */
}
Style #3:Code:if(1)
{
/* code */
}
I personally use style #1.Code:if(1)
{
/* code */
}
Printable View
Which style do programmers use more often?
Style #1:
Style #2:Code:if(1) {
/* code */
}
Style #3:Code:if(1)
{
/* code */
}
I personally use style #1.Code:if(1)
{
/* code */
}
I use #1 also.
C'mon, it's a poll! Put your preference in.
[edit]
dra, I mean.
[/edit]
first off, if is not a loop.
i use
Code:if (1) {
}
http://www.cs.bris.ac.uk/Teaching/Re...yle/style.htmlMine (Allman/BSD with more spaces):Code:Allman/BSD Horstmann GNU Whitesmith K&R
if (b) if (b) if (b) if (b) if (b) {
{ { x = 1; { { x = 1;
x = 1; y = 2; x = 1; x = 1; y = 2;
y = 2; } y = 2; y = 2; } else {
} else } } z = 3;
else { z = 3; else else }
{ } { {
z = 3; z = 3; z = 3;
} } }
Code:if ( b )
{
x = 1;
y = 2;
}
else
{
z = 3;
}
Mine is K&R except I put the else on a new line.
btw: whitesmith and gnu are really uglyCode:if (1){
printf("Hi\n");
}
else{
printf("Bye\n");
}
I have always preferred Allman, and had a really nice link to a site which had research on it demonstrating that Allman was better understood and created less errors to someone reading it. Sadly, I lost the link and have never been able to find it again.
K+R is an antique format that was devised to save paper when programs were printed out.
Of course, professionally, which format you use is often dictated by the coding standards in force at the company. I have successfully argued however, that people who are writing in an alien style are more likely to make mistakes and that therefore they should develop in their own style and that a code formatter be used to translate all of the completed work to the required format.
I used to use Allman but these days I use K&R. It looks nicer and I can still read it just as well. Also you'll find, thanks to linux, that lots of open source programs use that style.
Allman.
This Horstmann fellow was a sick, sick man...
woops! sorry about that. fixed.Quote:
Originally Posted by dwks
I pretty much stick to K&R for my own work, and whatever my current client dictates for their work (mostly Allman or derivatives).
K&R all the way, unless working in a team, in which case the decided style takes precedence (which is usually Allman).
i'm funny...if i'm trying to write rock solid, inpenetrable code, i use Allman...but if my primary goal is speed and performance, i use K&R...not in the same source file of course..i typically just default to Allman though.
Perspective, what style do you use? I see you voted "Other".
Like your number #1 but with a space before the opening bracket, as in my previous example. Its basically K&R but with the else on a new line and sometimes a little extra space to avoid clutter.Quote:
Originally Posted by dwks