|
 |
|
 |
|
View Poll Results: Which Style of curly braces layout do you prefer?
|
|
Style 1
|
  
|
7 |
30.43% |
|
Style 2
|
  
|
16 |
69.57% |
03-28-2003, 07:18 PM
|
#1 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,444
|
formatting
which style do you prefer?
Style 1:
Code:
if( var == 1) {
print("something);
} else {
print("something else");
}
Style 2:
Code:
if( var == 1)
{
print("something);
}
else
{
print("something else");
}
i'm mainly talking about the bracket layout here. which style do you prefer?
|
|
|
03-28-2003, 08:17 PM
|
#2 (permalink)
|
|
Regular Contributor
Join Date: Feb 2003
Posts: 120
|
I said style 1 because that is mainly how I do if/else if/else statements. but for fxns, i use style two. and loops, usually style one. constructors, style two.
|
|
|
03-28-2003, 08:44 PM
|
#3 (permalink)
|
|
GNU/Punk
Join Date: Jul 2002
Location: stuffs
Posts: 66
|
1 because im lazy and the other way requires you to hit enter one more time 
__________________
cd /usr/ports/misc/life && make install
|
|
|
03-28-2003, 09:24 PM
|
#4 (permalink)
|
|
Regular Contributor
Join Date: Mar 2003
Location: Las Vegas, NV
Posts: 127
|
#1 because that's just the way I've always done it, which makes it easier for me to read since I'm used to it. And I'm the only one who reads my own code, so I stick with the same style.
__________________
--Epsilon--
|
|
|
03-28-2003, 11:11 PM
|
#5 (permalink)
|
|
Non-profit Techie
Join Date: Dec 2002
Location: Mesa AZ
Posts: 76
|
Actually I do mine like this:
if( var == 1) {
print("something);
}
else {
print("something else");
}
Kind of a cross between 1 & 2
|
|
|
03-29-2003, 03:31 AM
|
#6 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,693
|
Style 2, everytime...
|
|
|
03-29-2003, 06:03 PM
|
#7 (permalink)
|
|
I am red.
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
|
wha wha whaaaa
I've never seen style 2 in my life. Style 1 all the way baby, I give so much space in my code it's like a giant field with little sheep like code snippets grazing about.
When and if I do a final version of anything I'll ususally make it tighter but compilers get rid of white space before they turn it into machine code anyway.
|
|
|
03-29-2003, 06:36 PM
|
#8 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
hint
Check my code in the c++ forums :th: .
|
|
|
03-29-2003, 06:40 PM
|
#9 (permalink)
|
|
Code Monkey
Join Date: Jan 2003
Posts: 57
|
Definitely style 2 since the editor I use will hide lines between braces and it works better with style 2.
|
|
|
03-29-2003, 06:44 PM
|
#10 (permalink)
|
|
Code Monkey
Join Date: Feb 2003
Location: Netherlands
Posts: 89
|
I use style #3.
Style #3 :
Code:
if(var==1)
print("something");
else
print("something else");
|
|
|
03-29-2003, 08:51 PM
|
#11 (permalink)
|
|
Registered User
Join Date: Mar 2003
Location: Between a rock and a hard place
Posts: 7
|
Never use style 3
Just becase you're allowed to leave off the braces, doesn't mean you should.
It's a bad habit, and will cause you endless headaches when you're trying to figure out why something is working, only to realize that a line of code was executing because it wasn't wrapped in an if statement as thought.
You lose nothing by adding braces, and you gain ease of reading and ease of maintainence
Just Friday I spent hours debugging a piece of code, and one of the main problems was exactly this... a coworker left braces off. Combine that with poor (IE no) indentation in the script and it was damn near impossible to stop
Trust me, I've been doing this 20+ years. Don'e leave the braces off
|
|
|
03-29-2003, 08:56 PM
|
#12 (permalink)
|
|
LOAD "*",8,1
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
|
there is alot more to coding style than mentioned above. luckily, i have a complete .indent.pro file to protect me from your styles.
Code:
--braces-after-if-line
--braces-after-struct-decl-line
--cuddle-do-while
--dont-cuddle-else
--indent-level2
--brace-indent0
--case-indentation0
--no-parameter-indentation
--struct-brace-indentation0
--blank-lines-after-declarations
--blank-lines-after-procedures
--leave-optional-blank-lines
--leave-preprocessor-space
--no-space-after-casts
--no-space-after-function-call-names
--no-space-after-parentheses
--no-space-after-for
--no-space-after-if
--no-space-after-while
--space-special-semicolon
--dont-break-function-decl-args
--dont-break-procedure-type
--continue-at-parentheses
--dont-format-comments
--dont-star-comments
--preserve-mtime
--tab-size2
--no-tabs
|
|
|
03-30-2003, 05:12 AM
|
#13 (permalink)
|
|
Code Monkey
Join Date: Feb 2003
Location: Netherlands
Posts: 89
|
Quote:
Originally posted by JJoSA
Never use style 3
Just becase you're allowed to leave off the braces, doesn't mean you should.
It's a bad habit, and will cause you endless headaches when you're trying to figure out why something is working, only to realize that a line of code was executing because it wasn't wrapped in an if statement as thought.
You lose nothing by adding braces, and you gain ease of reading and ease of maintainence
Just Friday I spent hours debugging a piece of code, and one of the main problems was exactly this... a coworker left braces off. Combine that with poor (IE no) indentation in the script and it was damn near impossible to stop
Trust me, I've been doing this 20+ years. Don'e leave the braces off
|
I have never had the problem of forgetting braces, Never.
Adding braces causes big and ugly code, If you have a problem
with forgetting braces with multiple statements than blame that
and not the braces.
|
|
|
03-30-2003, 06:02 AM
|
#14 (permalink)
|
|
Regular Contributor
Join Date: Feb 2003
Posts: 120
|
As long as you remember to use braces if you need two or more lines in your if statement; you'll be fine with style 3.
|
|
|
03-30-2003, 11:29 AM
|
#15 (permalink)
|
|
Registered User
Join Date: Mar 2003
Posts: 3
|
Code:
if($this) {
that
}
else {
this
}
loops(conditions)
{
this
}
function / class
{
here
}
For me it depends on how much code I'm putting between the curlies. If and else's I always use the same style, but for the others, if I'm only putting three lines, I use Style 1, if I'm putting lots of code, I use Style 2.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 04:06 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|