I use #2, but I'm thinking of switching to this format to ........ off all the #1 people
Edit: OMG! I can't believe the word filters blanked out the 'urinate' with a 'p' word! Who came up with this filter?Code:void func() { blah, blah... }
I use #2, but I'm thinking of switching to this format to ........ off all the #1 people
Edit: OMG! I can't believe the word filters blanked out the 'urinate' with a 'p' word! Who came up with this filter?Code:void func() { blah, blah... }
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
Style 2.
Style 2 is also standard at work. Makes the code easier to read.
Do we not know the names of these styles? Break down:
K&R
Code:int function() { if(blah) { code; } else { more code; } }
- Takes up less space.
- Orginiated from K&R and other early C advocates.
Allman
Code:int function() { if(blah) { code; } else { more code; } }
- Braces visually line up. Some editors will even connect them with a visible line.
- Indented blocks are clearer and higher-visibility.
- Consistent with scheme used for functions.
GNU
Code:int function() { if(blah) { code; } else { more code; } }
- Heck if I know.
I love Allman, myself. K&R causes the code to become bunched and harder to read, IMHO. Vertical space is not an issue with todays machines as it was back in the age of dinosaurs. Additionally, people need to grow a spine and learn where their tab key is. 3-7 bytes less, and a heck of a lot easier to work with.
Additionally, the K&R-ers and the Allman-ers should grab their pitchforks & torches, and go after the GNU-ers.
long time; /* know C? */
Unprecedented performance: Nothing ever ran this slow before.
Any sufficiently advanced bug is indistinguishable from a feature.
Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
The best way to accelerate an IBM is at 9.8 m/s/s.
recursion (re - cur' - zhun) n. 1. (see recursion)
I thought _that_ was GNU. Anyway, I think #1 is more compact. It will get difficult to constantly scroll up or down with style #2 (Unless you're using vim, which I don't).
Hey, I resemble that remark :-) And vertical space can still be an issue if you use a typical real-estate hogging IDE, your edit window scrunched by multiple toolbars and explorer panes. Another reason why GVim + make + bash is the ultimate IDE. ;-)
I'll boil the oil...Additionally, the K&R-ers and the Allman-ers should grab their pitchforks & torches, and go after the GNU-ers.
If you mostly code that way yourself, I suppose this is true. As someone who (excusively) uses a K&Rish style, I honestly find the allman harder to scan.
Only if you want to use little tiny fonts. And I would say because of widescreen monitors, it's the *horizontal* space that has increased the most drastically, eg. the view in my editor is 40x125.I love Allman, myself. K&R causes the code to become bunched and harder to read, IMHO. Vertical space is not an issue with todays machines as it was back in the age of dinosaurs.
I have no issue with this, actually:
or anything else that will fit tidily on one line. And I sometimes put braces on the same line as an instruction inside the block *and* double up if it's something nested like this:Code:void somefun(int *x) { if (*x%2) *x++; else *x+=2; }
Which allmanized would be almost *twice* as many lines. IMO C programmers may be more anal about this than programmers in other languages.Code:if (condition) { switch (var) { case; case; default; } }
Last edited by MK27; 05-23-2009 at 09:34 AM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
I'd vote for it
Clearly you have been brainwashed, like that South Park episode where the kid gets a shock for cursing. To me it's WAY WAY better than:
which I would consider symptomatic of brain death. You've replaced your mind with whitespace. I actually believe that people who predominantly use certian unnamed OS's, where a CLI seems like an abomination, have paid with diminished "reading comprehension" skills. Seriously.Code:if (condition) { switch (var) { case; case; default; } }
Last edited by MK27; 05-23-2009 at 03:12 PM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
It also took me a lot less time to read the Allman (or for that matter, the K&R) style version instead of the MK27...
Huh? I've seen just as much K&R and Allman in Linux as I have in Windows... I can't really tie one to the other, other than perhaps the fact that MSVS for C# enforces a crappy version of Allman.Originally Posted by MK27
long time; /* know C? */
Unprecedented performance: Nothing ever ran this slow before.
Any sufficiently advanced bug is indistinguishable from a feature.
Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
The best way to accelerate an IBM is at 9.8 m/s/s.
recursion (re - cur' - zhun) n. 1. (see recursion)
Just as horrible is this, a bit like the GNU one but worse, which I've seen from time to time:
Code:void foo(int i) { code; if (a == b) { code; } }
Fingers down the throat job.
I think you can put a signature here.
Last edited by MK27; 06-02-2009 at 08:19 AM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
That is the Whitesmiths style, pointed out in post #19.Originally Posted by Driver
So far, with the exception of the MK27 style, I find all these indent styles to be reasonable for reading, even though I would be reluctant to write with all but Allman and K&R. So much for "abominations".Originally Posted by MK27
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I am sure there is a whole pack of cowards here who totally empathize with the obvious (and elegant) logic of my indentation style and have even done similar things themselves, when allowed, but are afraid to speak up because it is too late -- history has spoken*.
This is like a thousand line project with 2 header files in allman.Code:/* command line arguments */ if (argc>1) { if (strlen(argv[1])>MPTH-1) { puts("Filename is too long!"); return 0; } if (argv[1][0]!='-') tmp=argv[1]; /* filenames starting with a dash will need ./ */ while ((opt=getopt(argc, argv, options))>0) switch (opt) { case ('?'): usage(argv[0]); return 0;
* but that doesn't make it right you fascists
Last edited by MK27; 06-02-2009 at 08:42 AM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge