![]() |
| |||||||
| View Poll Results: Which style of if do you use? | |||
| Style #1 | | 18 | 28.57% |
| Style #2 | | 37 | 58.73% |
| Style #3 | | 6 | 9.52% |
| Other | | 3 | 4.76% |
| Multiple Choice Poll. Voters: 63. You may not vote on this poll | |||
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,698
| Which style of if loops is most common? Style #1: Code: if(1) {
/* code */
}
Code: if(1)
{
/* code */
}
Code: if(1)
{
/* code */
}
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, nort, etc. |
| dwks is offline | |
| | #2 |
| Weak. Join Date: Apr 2005
Posts: 166
| I use #1 also. |
| dra is offline | |
| | #3 |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,698
| C'mon, it's a poll! Put your preference in. [edit] dra, I mean. [/edit]
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, nort, etc. Last edited by dwks; 08-20-2005 at 08:57 PM. |
| dwks is offline | |
| | #4 |
| Crazy Fool Join Date: Jan 2003 Location: Canada
Posts: 2,596
| first off, if is not a loop. i use Code: if (1) {
}
__________________ jeff.bagu.org - Terrain rendering and other random stuff |
| Perspective is offline | |
| | #5 |
| Just Lurking Join Date: Oct 2002
Posts: 5,005
| http://www.cs.bris.ac.uk/Teaching/Re...yle/style.html 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;
}
__________________ 7. It is easier to write an incorrect program than understand a correct one. 40. There are two ways to write error-free programs; only the third one works.* |
| Dave_Sinkula is offline | |
| | #6 |
| Registered User Join Date: May 2004
Posts: 1,362
| Mine is K&R except I put the else on a new line. Code: if (1){
printf("Hi\n");
}
else{
printf("Bye\n");
}
|
| sand_man is offline | |
| | #7 |
| It's full of stars Join Date: Aug 2001
Posts: 4,833
| 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.
__________________ Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream. |
| adrianxw is offline | |
| | #8 |
| Registered User Join Date: Jan 2002 Location: Cardiff
Posts: 2,219
| 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. |
| Brian is offline | |
| | #9 |
| Toaster Join Date: Aug 2001
Posts: 2,686
| Allman. This Horstmann fellow was a sick, sick man...
__________________ The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop. |
| Zach L. is offline | |
| | #10 | |
| Weak. Join Date: Apr 2005
Posts: 166
| Quote:
| |
| dra is offline | |
| | #11 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,680
| I pretty much stick to K&R for my own work, and whatever my current client dictates for their work (mostly Allman or derivatives). |
| Salem is offline | |
| | #12 |
| Supermassive black hole Join Date: Jul 2005 Location: South Wales, UK
Posts: 1,709
| K&R all the way, unless working in a team, in which case the decided style takes precedence (which is usually Allman).
__________________ Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife. - Mike McShaffry |
| ahluka is offline | |
| | #13 | |
| Registered User Join Date: Sep 2004
Posts: 720
| 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.
__________________ Quote:
| |
| misplaced is offline | |
| | #14 |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,698
| Perspective, what style do you use? I see you voted "Other".
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, nort, etc. |
| dwks is offline | |
| | #15 | |
| Crazy Fool Join Date: Jan 2003 Location: Canada
Posts: 2,596
| Quote:
__________________ jeff.bagu.org - Terrain rendering and other random stuff | |
| Perspective is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to handle multiple cases which use common code? | tmaxx | C Programming | 3 | 10-03-2008 07:42 AM |
| WM_CAPTION causing CreateWindowEx() to fail. | Necrofear | Windows Programming | 8 | 04-06-2007 08:23 AM |
| Button handler | Nephiroth | Windows Programming | 8 | 03-12-2006 06:23 AM |
| WS_EX_COMPOSITED style (double buffering) problems | JasonD | Windows Programming | 2 | 10-12-2004 11:21 AM |
| Tab Controls - API | -KEN- | Windows Programming | 7 | 06-02-2002 09:44 AM |