I use #2, but I'm thinking of switching to this format to ........ off all the #1 people :D
Edit: OMG! I can't believe the word filters blanked out the 'urinate' with a 'p' word! Who came up with this filter? :pCode:void func()
{
blah, blah...
}
Printable View
I use #2, but I'm thinking of switching to this format to ........ off all the #1 people :D
Edit: OMG! I can't believe the word filters blanked out the 'urinate' with a 'p' word! Who came up with this filter? :pCode:void func()
{
blah, blah...
}
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.
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).
Allman style is my favorite simply because it's easier to read and it looks more visually appealing to me.
GNU and Whitesmiths are hated styles >_<
And as for style #1, I don't resent it, but I don't really like it.
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...Quote:
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.Quote:
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; } }
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;
}
}
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.Quote:
Originally Posted by MK27
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.
That is the Whitesmiths style, pointed out in post #19.Quote:
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".Quote:
Originally Posted by MK27
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