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 */ }
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 */ }
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.
C'mon, it's a poll! Put your preference in.
[edit]
dra, I mean.
[/edit]
Last edited by dwks; 08-20-2005 at 08:57 PM.
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.
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; }
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.*
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.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
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...
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.
I pretty much stick to K&R for my own work, and whatever my current client dictates for their work (mostly Allman or derivatives).
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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
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.
i seem to have GCC 3.3.4
But how do i start it?
I dont have a menu for it or anything.
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.
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.Originally Posted by dwks