The Only Correct Indent Style

I know we discussed indent styles once before, but I figured we might as well do it again. This time, I figured we might as well make it a poll and see which of these styles appears to be the most popular one.

Since not everyone knows these styles by name, let me give you an example of each one to refresh your memory. Usually, most programmers only acknowledge one true indent style and consider all the other ones an unholy abomination unto God. So here are the styles to pick from:

K&R

if (x == y) {
    x++;
    foo();
} else {
    x--;
    bar();
}

Allman

if (x == y) 
{
    x++;
    foo();
} 
else 
{
    x--;
    bar();
}

Whitesmith

if (x == y) 
   {
   x++;
   foo();
   } 
else 
   {
   x--;
   bar();
   }

GNU

if (x == y) 
  {
     x++;
     foo();
  } 
else 
  {
     x--;
     bar();
  }

Horstman

if (x == y) 
{   x++;
    foo();
} 
else 
{   x--;
    bar();
}

Pico

if (x == y) {
    x++;
    foo(); } 
else {
    x--;
    bar(); }

Banner

if (x == y) {
    x++;
    foo(); 
    } 
else {
    x--;
    bar(); 
    }
The only correct indent style
View Results

I actually prefer the Allman style. The braces should go underneath the opening block statement. I hate when the K&R people put them on the same line. All the other styles are just to bizarre.

How about you? Which style do you prefer?

This entry was posted in Uncategorized. Bookmark the permalink.



104 Responses to The Only Correct Indent Style

  1. mcai8sh4 UNITED KINGDOM Opera Linux Terminalist says:

    I’ve always gone the Allman way. Just seems neater and easier to read.
    My main reference book is K&R (the bible), but I’ve never used their indent style. Besides, I code mainly in Vim, and the auto-indent happens to follow the Allman style.
    To be honest I’ve never really considered my indent style. My programs are only really ever seen by me, and so in general they’re fairly sloppy, usually filled with useless comments, and var names that have no reasoning. Everything just seems to get mildly obfuscated by the time it reaches my fingers.

    Of late, I’ve been writing programs for a microcontroller, since this is fairly new to me, I’m trying to write better code to help the learning process, but it doesn’t always work. The only think I am consistent with is my indentation style.

    Reply  |  Quote
  2. For me, it’s GNU style because it’s what I am used to. This is from using Emacs and GNU indent all the time. Allman (bsd) style would be my second favorite.

    If someone sends me ugly code to read, I run it through indent first.

    Reply  |  Quote
  3. Steve CANADA Mozilla Firefox Windows Terminalist says:

    Why the hell is K&R winning? That’s got to be one of the worst indent styles. Jesus. Please, I hope never to work as a programmer on code that one of you who voted for that have done. Seriously.

    I agree with Allman or Gnu…both very similar except for the indents before the conditional brackets.

    Reply  |  Quote
  4. Ian Clifton UNITED STATES Mozilla Firefox Ubuntu Linux says:

    Allman… but damn some of those others are ugly :D

    Reply  |  Quote
  5. Allman.. but forced to K&R at Work (only exception: functions and classes are more Allman-Like)

    I think Allman is much more readable… everything besides those two is just insane.

    Reply  |  Quote
  6. Matt Doar UNITED STATES Mozilla Firefox Mac OS says:

    K&R is more compact but just as easy to scan as Allman. It’s my default style, but I go with whatever a project is using. If a project can’t agree on a style, it’s got bigger problems.

    Reply  |  Quote
  7. Yeah, Allman is my ideal choice. I like K&R the best after that but with a new line at the end of a closing bracket instead of piling another conditional in front of it which I think is ugly.

    Reply  |  Quote
  8. Tino UNITED STATES Mozilla Firefox Ubuntu Linux Terminalist says:

    K&R is simply the one obvious choice. This is how the people that invented the language wrote the code, and if you are using their syntax, why do you second-guess their indentation? They knew what they were doing.

    Just like written text, code should be divided into logical segments/paragraphs by using empty lines as whitespace. With Allman this segmentation tends to be lost among the surplus single bracket lines. As far as I have seen, most of the people who promote styles other than K&R tend not to have understood what empty lines means in the code, and that proper use of whitespace can make the code more readable.

    Besides that, the question of indentation is more than anything a question of habit. Most of the “this style is better because”-arguments are ex-facto constructions. People should just stick with the original style and stop inventing their own perversions of it.

    Reply  |  Quote
  9. Chrissy UNITED STATES Mozilla Firefox Mac OS says:

    Allman was what I was taught when I learned Java, and it makes sense if you’re going to have a lot of nested brackets. But since I mostly write CSS, I prefer K&R

    Reply  |  Quote
  10. Dan UNITED STATES Konqueror Linux says:

    Allman FTW

    Reply  |  Quote
  11. Mats Rauhala FINLAND Mozilla Firefox Linux says:

    I don’t have a precedence to any of the styles. All of them are neat and readable, if you try. After using K&R for years all the rest were difficult to read, until I started practising Allman.

    Reply  |  Quote
  12. Mart SINGAPORE Mozilla Firefox Windows Terminalist says:

    Allman for me! I prefer to see code blocks in encapsulated by braces in that matter.

    Reply  |  Quote
  13. freelancer SWEDEN Mozilla Firefox Windows Terminalist says:

    “I actually prefer the K&R style. The braces should go on the same line as the opening block statement. I hate when the Allman people put them underneath. All the other styles are just too bizarre.”

    There, fixed your statement, Luke :P

    Reply  |  Quote
  14. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

    Heh, it seems that this is pretty much an Allman vs K&R thread. When I checked this post yesterday K&R was winning by like 5 votes despite the comments being very skewed towards Allman. Today Allman is ahead, but only by few votes.

    [quote post=”2929″]If a project can’t agree on a style, it’s got bigger problems. [/quote]

    Very true. If code is handed down to me, I will try to follow whatever indent style they were using. But if I started the project, you can pretty much bet your sweet ass it is going to be Allman.

    @Tino: Your argument that:

    [quote post=”2929″]the question of indentation is more than anything a question of habit. Most of the “this style is better because”-arguments are ex-facto constructions.[/quote]

    Would be much stronger if you didn’t say this in your previous paragraph:

    [quote post=”2929″]Just like written text, code should be divided into logical segments/paragraphs by using empty lines as whitespace. With Allman this segmentation tends to be lost among the surplus single bracket lines. As far as I have seen, most of the people who promote styles other than K&R tend not to have understood what empty lines means in the code, and that proper use of whitespace can make the code more readable.[/quote]

    So you’re like “K&R is better because blah blah blah, and besides your counter argument is invalid because it is a question of habit and comparing styles makes no sense”.

    But you are right – it is a question of habit and preference. As far as I can tell, indent style really has no impact on your performance, and as long as it is consistent throughout the code it has minimal impact on readability. So yeah, this discussion is one of these little petty things that we programmers like to argue about.

    It’s like the vi vs emacs debate – most people are like “who the hell cares about this” but we can go on for hours comparing features, philosophy, design choices, performance, ease of issuing commands, modal editing vs complex keystrokes and so on. :P

    As for K&R and whitespace – that is a good argument for K&R. But the point of Allman style is to make the start of the block more distinctive. So function invocations, loop statements and etc have an extra line below them which contains the brace and white space. It allows to identify these rather important statements at a glance just by the way they are on a line of their own.

    You can do the same thing with K&R buy looking at the indentation but it is not as clear.

    @Chrissy: Yeah, I noticed that like 90% of CSS on the web out there is indented K&R style. WTF?

    Oh, and I’m part of the problem – since I usually steal a lot of CSS from pre-made templates, samples and etc I usually keep my stylesheets in K&R for consistency.

    Reply  |  Quote
  15. naum UNITED STATES Mozilla Firefox Mac OS Terminalist says:

    K & R

    Better than Allman because (a) it spares the superfluous newlines for whitespace and/or comments and (b) visually more aesthetic with nested blocks…

    As stated, please adhere to the indent style when modifying code… …nothing worse than code that is a mishmesh of various indent styles…

    And for the love of Gates, tabs to spaces please. Nothing is more annoying than editing source code that’s mangled because editor tab settings vary…

    Reply  |  Quote
  16. Nick UNITED STATES Mozilla Firefox Gentoo Linux says:

    K & R. I can deal with Allman too but it just seems wasteful in regards to vertical space. I’ve never seen the pico style before but I kinda like it. In regards to GNU per /usr/src/linux/Documentation/CodingStyle:

    First off, I’d suggest printing out a copy of the GNU coding standards, and NOT read it. Burn them, it’s a great symbolic gesture.

    Reply  |  Quote
  17. Tino UNITED STATES Mozilla Firefox Ubuntu Linux Terminalist says:

    @Nick: Thanks for the link to the Linux kernel coding style. I had not read it before, and like much of Linus stuff it was both fun and insightful.

    @Luke: Yeah, my comment sounded a bit contradictive, but hey, this is holy war, there is no room for rationality :D

    [quote comment=”11980″]But the point of Allman style is to make the start of the block more distinctive. So function invocations, loop statements and etc have an extra line below them which contains the brace and white space. It allows to identify these rather important statements at a glance just by the way they are on a line of their own.[/quote]

    But not all loop statements and if-branches are important. K&R rather lets you use whitespace for emphasis where it helps the reader the most, rather than to abide by rules.

    In K&R the function declarations are ~ headlines, and empty lines are ~ paragraphs. You can put the paragraphs where they make the most sense for your code.

    Allman, on the other hand, is as if someone proposes for written language that “Hey, lets turn every sentence that begins with ‘For, While, If’ into a headline.”

    And you see, ladies and gentlemen, why would Chewbacca want to live on Endor with a bunch of two-foot tall Ewoks? It does not make sense! ;)

    Reply  |  Quote
  18. David Cumps BELGIUM Mozilla Firefox Windows says:

    That’d be Allman for me, I kinda made the switch from K&R when I moved onto C# programming and stuck with it ever since.

    Code is art, and art is in the eye of the beholder :)

    Reply  |  Quote
  19. Boris Said UNITED STATES Mozilla Firefox Windows says:

    I like Allman because the code just look neater, and the braces are easier to read and understand with more complex coding.

    Reply  |  Quote
  20. Hannes Mozilla Firefox Linux says:

    I use K&R and sometimes pico as I like compactness. I find the extra line with a single character in Allman reel weerd and hard to scan over (though I’ve learned that it’s really just a matter of what each individual is used to).

    But unlike most ;-) programmers I’m not fanatic about it and I see the logic behind most of the other styles. Allman is indeed taught in all the school and university textbooks I know, but I agree with Tino: “K&R is the obvious choice”

    Reply  |  Quote
  21. John Galt UNITED STATES Mozilla Firefox Windows says:

    Allman is the ONLY indent style you should be using. Visual Studio (best IDE out there) has it as a default, as does ANSI standard. The only reason K&R used to be popular, is because back in the 80’s all programmers had were crappy 24 line monitors, so you had to preserve space. If you can’t afford a decent 20″ or bigger monitor these days, you’ve got bigger problems than indentation… A serious programmer needs at least 2 or three monitors anyway…

    K&R is for amateurs – listen to professionals and stick to Allman’s.

    Reply  |  Quote
  22. Gary UNITED KINGDOM Google Chrome Windows says:

    Allman is the clear winner for me. Code readability is key, and using an extra line is a small price to pay, especially given the size of modern monitors.

    Reply  |  Quote
  23. Leeroy UNITED STATES Mozilla Firefox Windows says:

    Allman. K&R is a travesty. People trying to save that one extra line at the expense of clarity should be shot.

    You like saving space so much, why don’t you go a step further and just write the entire block on one line.

    if(x==y){x++;foo();}else{x–;bar();}

    As for those other styles WTF, are they TRYING to be ridiculous?

    @ tino “This is how the people that invented the language wrote the code, and if you are using their syntax, why do you second-guess their indentation? They knew what they were doing.”

    You do know they had tiny green monitors, right? They tried to conserve a bit of space, and I don’t blame them, but today’s programmers have no excuse.

    Reply  |  Quote
  24. Karl SWITZERLAND Mozilla Firefox Mac OS says:

    For me, a slightly modified K&R.

    One of the advantages (IMHO) that proponents of Allman quote, is the extra readability that the blank line gives between a function header and body.

    e.g.

    int main ()
    {
    statement 1;
    statement 2;
    }

    I say, adjust K&R like this

    int main () {

    statement 1;
    statement 2;

    }

    For me, this gives the extra readability and the beauty of K&R.

    Reply  |  Quote
  25. Bo UNITED STATES Google Chrome Linux says:

    I like both Allman and K&R. But, after much “testing” and consideration, I choose K&R.

    It’s flexible. Add whitespace if you want.

    It’s easier to read (for me anyway). I fell like having the opening brace out of the way is nice. I don’t need it to see what’s going on.

    Reply  |  Quote
  26. Brian UNITED STATES Internet Explorer Windows says:

    Lately, coding in Java, I’ve been using a combination of Allman and K&R.

    I use K&R for class declarations, and use Allman for everything else. This makes it easy to just glance over the code and tell if a declaration is a class.

    Reply  |  Quote
  27. makeSense CANADA Internet Explorer Windows says:

    I love ruby style. There is no brace at all! Simple, clear and elegant. That is the way a language should have been designed.

    Reply  |  Quote
  28. JC AUSTRALIA Google Chrome Windows says:

    New projects: Allman.

    Exceptions: CSS, Javascript closures (and similar constructs elsewhere) can be K&R. These should typically be small blocks.

    End of debate. Readability is the most important thing, followed by consistency. K&R proponents should try something new.

    Established Projects: Use the project standard, or if none, as above.

    Tabs vs spaces: Easy. On any line, tabs to indent, spaces to align. And aligning should be an exception. Everybody is happy. If you don’t know what that means then your opinion is invalid. If you’re to lazy to do this properly then you wouldn’t work with me.

    Reply  |  Quote
  29. Marcos Sartori Google Chrome Windows says:

    Everytime I get my hands in a code written using Allman, I have to reindent it using astyle back to K&R if I want to perform any modification larger then a printf.
    Allman is horrible to read, blocks get confused, even the simplest code looks huge using this style. The Only place I accept brackets on an empty line is when opening classes definitions.

    The worst part is that my boss is an allman. And every code I write I have to indent and reindent back to allman.

    Reply  |  Quote
  30. Wookie AUSTRALIA Mozilla Firefox Windows says:

    Allman for PHP, and K&R for JavaScript – makes it easier to tell them apart at a quick glance. Javascript’s naming conventions lend themselves to a more compact code, and since a .js file counts as bandwidth, it’s good to make it as small as possible.

    PHP:

    function print_foo($text_data)
    {
    return $something ."/". $in_concat ."/". $with_something_else;
    }

    Javascript:

    function printFoo(textData) {
    return something +"/"+ inConcat +"/"+ withSomethingElse;
    }

    Reply  |  Quote
  31. Nikos Mozilla Firefox Windows says:

    @Carl: I agree 100%! I used to write in Allman and then moved into a project that
    used K&R. at first I was annoyed but then it grew on me and finally I settled on the ‘modified’ version. It’s both clear and flexible since you can skip the spaces for really simple statements.

    Reply  |  Quote
  32. Dave UNITED STATES Mozilla Firefox Linux says:

    Allman. The opening brace should be below its statement. The extra line and the fact that the braces line up vertically makes it easier to tell the structure of the code. Also I insist that the braces must be at the same indentation level as the associated control statement or function declaration, so those other weird styles are definitely out. I once worked with a guy who liked Horstmann, and found it to be acceptable to me. K&R tends to drive me nuts; its compactness inevitably makes code harder to read – I consider conciseness to be primarily a trait of the code itself, not the indent style around it.

    Reply  |  Quote
  33. Mark UNITED STATES Mozilla Firefox Windows says:

    So far, no one has commented on the fact the curly braces are not actually optional lexical elements of the iterative and conditional control structures. The curly braces are part of a completely different grammatical production known as <compound-statement> (a.k.a. <block>).

    <compound-statement> ::= '{' <statement-list> '}'

    <statement-list> ::= <statement> | <statement-list> <statement>

    The grammatical productions for <if> and <if-else> are:

    <if> ::= "if" '(' <expression> ')' <statement>

    <if-else> ::= "if" '(' <expression> ')' <statement> "else" <statement>

    If the curly braces were optional elements of the control structures, the grammatical productions for <if> and <if-else> would look like:

    <if> ::= "if" '(' <expression> ')' <statement> | "{" <statement-list> "}"

    <if-else> ::= "if" '(' <expression> ')' <statement> | "{" <statement-list> "}" "else" <statement> | "{" <statement-list> "}"

    The reason why we can use the curly braces to control a list of statements with a control structure is because the non-terminal symbol for the <compound-statement> grammatical production resides on the right-hand side of the <statement> grammatical production.

    <statement> ::= <if> |
    <if-else> |
    <for> |
    <do-while> |
    <compound-statement> |
    ...

    With the above said, if we follow the rule that any statement that is controlled by a control structure must be indented on the next line, then the only correct indent style is GNU. The GNU indent style is the only style that recognizes that <compound-statement> is a actually separate statement that controls a statement list.

    One last thing: there is exactly one control structure in C++, Java, an C# for which the curly braces are in fact lexical elements; namely, <try-catch-finally>.

    Reply  |  Quote
  34. XP1 UNITED STATES Opera Windows says:
    
    "Just like written text, code should be divided into logical
    segments/paragraphs"
    
    Paragraphs, you say?
    You mean like this?
    
    if (x == y)
        {    x++; foo(); var O; var Q = new Date(); var R =
         Q.getMonth() + 1; T = {}; j = p[g]; Z = P(a[g], j, Z);
         o = "";}
    else
        {    x--; bar();}
    
    Well, they do look like indented paragraphs, right?
    
    Eureka! I think that I may have just invented a new style:
    
    if (x == y)
        {x++; foo(); var O; var Q = new Date(); var R =
         Q.getMonth() + 1; T = {}; j = p[g]; Z = P(a[g], j, Z);
         o = "";}
    else
        {x--; bar();}
    
    I shall call it the "block quotation style" because it looks like
    an indented block quotation with quotation marks in
    written text, like this:
        "This is a block quotation. ...
         ...
         ...
         ... Blah, blah, blah."
    
    Or if you want something easier to read, try this,
    the block quotation list style:
    
    if (x == y)
        {x++;
         foo();
         var O;
         var Q = new Date();
         var R = Q.getMonth() + 1;
         T = {};
         j = p[g];
         Z = P(a[g], j, Z);
         o = "";}
    else
        {x--;
         bar();}
    
    The next statement goes on a new line, like a list.
    
    Enjoy!
    
    Reply  |  Quote
  35. redlenses UNITED STATES Google Chrome Windows says:

    Allman is my favorite. I dislike K&R

    if (x = 20)
    {
    blah;
    }
    else if (y = 10)
    {
    blah;
    }
    else // (x != 20 && y != 10)
    {
    blah;
    }

    is easier for me to read than:
    if (x = 20) {
    blah;
    } else if (y = 10) {
    blah;
    } else { // (x != 20 && y != 10)
    blah;
    }

    Reply  |  Quote
  36. holygrail LATVIA Mozilla Firefox Ubuntu Linux says:

    Of course I prefer K&R, but on my current work we use that ugly Allman style… not a big deal, in fact, but obviously K&R is the best. Anything else just ins’t made for white people.

    Reply  |  Quote
  37. Kon Mozilla Firefox Windows says:

    For some this might look something small. I believe it is something that has to do with logic and how do we perceive things. In all my works I had to do use the ugly old fashioned K&R style , but when I could I used Allman style and although that weren’t the policy, every one else could read my code easier so they didn’t complained. I am very happy to see that Allman style is gaining, and maybe in few years will be the programming industry main coding style.

    Reply  |  Quote
  38. Jeremy UNITED STATES Google Chrome Mac OS says:

    K&R style is that hard to read? Really? Try reading “monkey pounded on the tab key and spacebar randomly” style and get back to me. Or “10 programmers with 10 different styles and text editor configurations have completely scrambled this code” style.

    If you’re using any vaguely sane indentation style consistently, I seriously doubt your choice of style is the reason your code is unreadable.

    I’m waiting for the “K&R doomed our project!” anecdotes though. Superstition-driven development indeed.

    Reply  |  Quote
  39. I’m tired of reading the bias and pointless feuds over this. If you’re going to make arguments for one side, make sure you are actually comparing the orginal stules, not some variation. I just read several comments using Allman style without indents. One of which compared that to K&R without indent (which is a bit unfair). Another person also acted like a complete jerk and removed newlines in K&R completely to twist an argument. I also saw a racial comment in defense of K&R which is just inconsiderate in the 21st century.

    Let’s making sensible arguments here. Screen estate isn’t the main goal of K&R, and I feel like it never really was. Code needs to be properly grouped, and the best way to do this is by sectioning lines off and isolating it with new lines. There is no purpose to having an extranneous new lines that confuse this simple aspect of organization. I’m seeing a lot of people favoring Allman and not using any indentation whatsoever. Indentation is the main key to clearly seeing blocks, not curly braces. I would loke to see an argument that actually counters this.

    Changing the topic a bit, I want to see Horstman catch on. It has the benefeits of both. styles.

    Reply  |  Quote
  40. lake393 UNITED STATES Mozilla Firefox Windows says:

    Brandon,

    When you are complaining that various examples of code in this thread are not indented properly, I think you are forgetting that HTML does not preserve whitespace.

    Those people may very well have indented their examples, but the spaces were eliminated during the posting process. In order for spaces to be preserved, HTML requires <pre> tags (or an equivalent CSS attribute) to surround the text.

    For example, this blog makes it tricky to keep your indenting. I am indenting the below example, to no avail.

    int main(int argc, char**argv)
    {
    std::cout << "Hello world!" << std::endl;
    return 0;
    }

    But in the following case, I forced the lines to be indented by using nonbreaking spaces, a special HTML character code (&nbsp;).

    int main(int argc, char**argv)
    {
        std::cout << "Hello world!" << std::endl;
        return 0;
    }

    P.S. Allman is the best style.

    Reply  |  Quote
  41. John Galt UNITED STATES Mozilla Firefox Windows says:

    Brandon Cheng (gluxon) wrote:

    I’m tired of reading the bias and pointless feuds over this. If you’re going to make arguments for one side, make sure you are actually comparing the orginal stules, not some variation. I just read several comments using Allman style without indents.

    You do realize that’s just HTML removing whitespace, because the poster didn’t enclose it inside ‘code’ tags?

    Reply  |  Quote
  42. sigfried GERMANY Mozilla Firefox Windows says:

    I prefer Allmann. Blocks are easier to identify viusally by level of indentation.

    Reply  |  Quote
  43. devbytes PHILIPPINES Google Chrome Windows says:

    It’s Allman dude! I’m really really frustrated when reading K&R. It makes my eyes squint :(

    Reply  |  Quote
  44. compiler SPAIN Google Chrome Linux says:

    As a Python programmer, “forced” to code in C, C++ or Java, I would choose Allman with no doubt.

    I imagine that K&R places it in the same line to distinguish them from { } scope operators:


      (...)
      {
        int i;
        (...)
      } // i "dies" here
      (...)

    But it’s not enough for me that difference. I choose Allman Style, with 4 spaces as indent (soft-tabs) using Vim to code and autoindent + to indent :P

    Reply  |  Quote
  45. Tino SWEDEN Google Chrome Linux Terminalist says:

    It is funny how this one post just keeps on going and going with comments. It is almost as if this the issue was controversial…

    @compiler
    If you identify yourself “as a Python programmer”, shouldn’t your preferred style be Pico? (see original post), it seems quite similar to Python.

    Actually, you can do even better. Just use Python indentation and hack together a schellscript to be run during make that uses the indentation to add missing brackets during compile time :).

    Reply  |  Quote
  46. Jamal CANADA Mozilla Firefox Windows says:

    I have been programming using the Allman style, but have decided to try out Horstmann for a while. It may take a little getting used to looking at, but I love how the braces are aligned AND it saves you a line. I really can’t stand the look of K&R, but don’t particularly like how Allman creates verbose vertical whitepsace at times.

    Reply  |  Quote
  47. MeMyselfAndI GERMANY Google Chrome Linux says:

    when I started learning C Allman always made most sense to me – without knowing that it was “Allman”. For me it feels most intuitive and natural. Most will argue that K&R is the original and that Allman is a waste of space but I think that’s a low price for maintainability. I’m surprised that it got most of the votes now because “out there” (work and especially in the open source area) you mostly see K&R or Stroustrup style. I never could convince people to use Allman. So I had to to compromise and also got used coding in other styles. Jeet Kune Do or Bruce Lee style if you will. :P
    In the end I don’t think you can really argue about it because it all comes down to personal preference.

    Reply  |  Quote
  48. Chris UNITED STATES Google Chrome Windows says:

    Allman is great for the programming labs at university for helping students new to programming better understand syntax. And that’s why I enforce it in the Lab and grading. Once you start getting past a few hundred lines of code in your entire body of work, K&R is the obvious choice.

    The others? Kids are so cute these days…

    Reply  |  Quote
  49. Marvin CANADA Mozilla Firefox Ubuntu Linux says:

    How about Whitesmith’s style for CSS?

    body
    {
    background-color: #333333;
    color: #009999;
    /* blah blah */
    /* blah blah */
    }

    Reply  |  Quote
  50. Marvin CANADA Mozilla Firefox Ubuntu Linux says:

    There is no right way imo. I suggest to use any style so long it’s to increase code readability, as it’s humans who have to read the code to understand. I sometimes use K&R to indent elements of an array to assign to a variable in PHP. Also for some closures. For anything else, such as classes, control structure, All man all the way.

    (Hmm, the code tag is worse than I thought.) Anyway, below is “suppose” to be whiteman style, this comment form doesn’t seem to allow whitespace indentation.
    body
    {
    background-color: #333333;
    color: #009999;
    /* blah blah */
    /* blah blah */
    }
    p.small
    {
    color: silver;
    font-size: 9px;
    }

    Makes finding styles in large blocks of CSS code easier IMO. For anything else, I prefer ALLMAN.

    Reply  |  Quote
  51. Pingback: The C Programming Language | TomHartung.com UNITED STATES WordPress

  52. Pingback: The C Programming Language | TomWHartung.com UNITED STATES WordPress

  53. Christian UNITED STATES Google Chrome Windows says:

    K&R if you know what you’re doing, Allman if you are having trouble reading code. It’s really a non-issue since most IDEs will let you auto format it to your style of choice with the press of a button.

    Reply  |  Quote
  54. Chris B CANADA Mozilla Firefox Windows says:

    ALLMAN style is by far the best… and I wish it was made the defacto standard for languages like Java, C++, and C# because I’m tired of being told to do it the K&R way.

    The reason some of the other styles were invented was to save space on screen by reducing the number of lines of code. This allowed book publishers to save some paper at the cost of reduced readability.

    Bottom line: Allman style is the easiest to read and the most “foolproof”. You are less likely to forget an opening brace using Allman style, and it’s easier to work with blocks of code. Start spreading the word and get people to switch back to this style! (It is standard at Microsoft by the way.)

    Reply  |  Quote
  55. Matt Doar Google Chrome Mac OS says:

    “This allowed book publishers to save some paper at the cost of reduced readability.”

    That seems rather unlikely to me. Saving space on an older screen so you could see more code is more likely.

    Reply  |  Quote
  56. Chris B CANADA Mozilla Firefox Windows says:

    @ Matt Doar:

    Fair enough. Whether it’s page space in textbooks or screen space on tiny low resolution displays from the 1970’s, the K&R style of formatting tries to solve a problem that is no longer a problem at the expense of making code more difficult to read. The notion of “saving lines of code” is outdated.

    When looking at other coding styles besides Allman, they all have serious drawbacks:

    – K&R looks awful (the code looks broken), wrecks the block structure of the code, and makes it easy to forget opening braces by making them difficult and unpredictable to locate. (Since every line is a different length.)

    – GNU requires too many tabs and too much maintenance regarding the indenting. It also wrecks the block structure of the code by creating an imaginary additional indent “level” that does nothing.

    – Horstman is horrendous because you can’t easily copy/paste code lines around without blowing away the braces.

    – Pico and Banner are a “dog’s breakfast” to try and read. Compact yes, but horrific to look at and likely the cause of most of the world’s programming bugs.

    – Whitesmith is an inaccurate/failed version of Allman because the braces that delineate the start and end of the block are not where the actual start and end of the block is. The braces are simply at the wrong level.

    The only drawback to using Allman style is that the code is spread over more lines, a problem long since resolved with larger, higher resolution monitors, and the use of classes to break code into smaller more manageable chunks.

    Reply  |  Quote
  57. John Galt UNITED STATES Mozilla Firefox Windows says:

    Simply put – anyone advocating coding style other than Allman is a complete tool. Glad to see it’s beating ridiculous K&R by almost 100%…

    Reply  |  Quote
  58. Jeremy UNITED STATES Safari Mac OS says:

    @ Chris B:

    You must not work on the same codebases I do. I feel bad when a file pushes into the thousands of lines, but I work with an open source project where multi-thousand-line functions are the norm. I often have to scroll back and forth through pages of code just to figure out when a mutex is locked and unlocked.

    Of course, I contend fixing that would do far more for the code’s readability than any indentation style can.

    Reply  |  Quote
  59. Chris B CANADA Mozilla Firefox Windows says:

    @ Jeremy:

    I guess I would strongly question how that code base was designed and why it has functions with over a thousand lines of code in them. As you suggested, it sounds like there’s more wrong there than any particular indenting style alone can fix.

    Another point I wanted to mention was ROW LENGTH. Some of the most unreadable code that I’ve ever seen is unreadable because of artificially restrictive row lengths on the code lines. Instead of having one easy to read line, it gets split into two or even three lines of code. While it may be true that humans prefer narrow columns when reading novels, programmers prefer to maintain the block and command structure in their code. If a command statement such as a compound IF can be kept to one line instead of two, it becomes more readable. If a function call displays all arguments passed in on the same line, it’s easier to read than having them waterfall underneath.

    I guess the three areas of programming I would change (if I could) is the following:

    1. Allman style indenting would be the standard for all languages that use braces.

    2. Row lengths would be increased to take advantage of wide screen monitors and reduce unnecessary line continuations in code.

    3. I would beat programmers over the head with a stick for not putting comments in their code. (Arguably my greatest pet peeve.)

    To date, there has never been a software project that had too much documentation. 99.9% of software projects don’t have enough or don’t have any. Having been put into the “wonderful” position of having to maintain other programmer’s junk on several occasions, I’m the guy that companies hire to tell them how their system actually works (since nobody understands it) and to document it so that future developers have an easy job. I can literally pick up a piece of my code from 10 years ago, look at a few of my comments, know exactly what I need to do, and pick up where I left off without missing a beat. But I digress…

    Reply  |  Quote
  60. Chris B CANADA Mozilla Firefox Windows says:

    That should have said “IF statements with multiple conditions” not “compound IF statements”. ^^^

    Example:

    if(color == “BLUE” || color == “RED” || color == “GREEN)
    {
    …doSomething();
    }

    Example:

    x = object.myFunction(longArgumentName1, longArgumentName2, longArgumentName3);

    Reply  |  Quote
  61. James UNITED STATES Mozilla Firefox Windows says:

    When I first learned C, the professor used the K&R style, but when I wrote my code, it looked like the Allman style. It just seemed more organized to me. It was easier for me to keep track of the braces. My professor would comment about how easy it was to read my code (I assumed it was because I coded so well–maybe it was just the coding style).
    I use the same style whether I’m in C, C++, C#, or Java.

    Reply  |  Quote
  62. Chris B. CANADA Mozilla Firefox Windows says:

    @James:

    I agree. I was taught to use the Allman style in school, and it was the default “template” in Visual Studio for writing code when I was in school. Whenever an editor tries to enforce a K&R style, I change the template right away.

    I’ve noticed that the K&R community has been trying very hard to foist their style on everyone, and I truly believe that over the long run it will lose out to the Allman style.

    A standard is determined by what the majority of people want to use, not what a small group of eggheads in ivory towers think the world should use. That’s why it isn’t surprising that Allman style is the preferred style. Allman style is what people want to use because it’s more natural, easier to read, and less prone to bugs. Those factors make it the clear winner on indenting style and brace location.

    Reply  |  Quote
  63. Danny Google Chrome Windows says:

    @ Chris B:
    I was really excited when a certain software company that discontinued one of their products placed their code on their website. They announced it was open source. The code was in C++; there were two header files and four implementation files. One of the files was over 54,000 lines of code. All the source code was written in a sort of K&R style with no blank spaces between functions, no whitespace in expressions, and not one comment.
    What a nightmare!

    Reply  |  Quote
  64. Tino SWEDEN Google Chrome Linux Terminalist says:

    @ Danny:

    Had you been happier with 75,000 lines of c++ in Allman style instead? It hardly is the K&R style that is the problem of that code. Also, why even complain about the K&R style? Just use one of the myriad of tools to re-indent the files for you. Indentation style is really only an issue when working on collaborative projects.

    Chris B. wrote:

    I’ve noticed that the K&R community has been trying very hard to foist their style on everyone, and I truly believe that over the long run it will lose out to the Allman style.

    This is a complete fabrication of history. The K&R style was the original style from the birth of C. It is these measly Allman followers who have since come along and now try to force their ugly context-breaking whitespaces on everyone. I use K&R so that I can proudly insert empty lines under my control statements precisely when I mean to do so, so that I can group statements by context, not by syntax.

    Reply  |  Quote
  65. Luis Henrique Loss Google Chrome Windows says:

    I used to program, on 1980s, with Algol and Pascal. It used “begin” and “end” instead of { and }, and they was aligned to block code. The first C courses I attended, in 1984 used WhiteSmith, and I get used with it, specially because it used the same identation as it predecessors Algol and Pascal. For me it makes more sense to have the signs (or reserver words), that starts and end the block, alignet to the block – these signs belongs to the block!!! Why put them away of the block? Well, once someone gets used with some style, it is difficult to change – it is a matter of personal visibility and fast code interpretation. For me, Allman is barely “acceptable”, but the others styles that places the braces elsewere… What the hell they creators had in mind?!?!? And a lot of new fool programmers got used with them!!! Fortunately, good editors can convert easily from one style to another. I like to use UltraEdit, from IDM Computer Solutions, Inc.

    Reply  |  Quote
  66. Anon CANADA Mozilla Firefox Linux says:

    i_like(Pico);{
    everyone_else(gasps);}

    Reply  |  Quote
  67. Rhiakath Mozilla Firefox Ubuntu Linux says:

    int main ( int argc, char *argv[] )
    {
    printf ( "Whitesmith all the way\n" );
    printf ( "Allman a second best\n" );
    return 0;
    }

    Reply  |  Quote
  68. Brent UNITED STATES Google Chrome Windows says:

    Holy sht K&R is disgusting. Allman is clearly the choice of the mentally superior crowd. There’s simply no logical benefit to placing a brace on the end of the line instead of at the beginning of the next, if you’re going to have a blank line after the K&R version anyway… which you should, because this is just fcking hideous:

    void thisCoderHasBadStyle() {
      string noBlankLinez4Me;
      if (noBlankLinez4Me == "ugly") {
        cout <<"damn this is some gross code.";
        cout <<"just a cluster of sht.";
      }
    }

    Reply  |  Quote
  69. Wes UNITED STATES Opera Linux says:

    I will say that my preference is a mashup:
    Allman opening, with banner closing.
    I’ve heard this mentioned as a banner variant, but I could just as easily call it Allman Offest, Allman Banner, or something similar. Or whatever I please for a name: It’s not like it would be obvious what I meant by the name without showing anyway.

    I am curious as to what others think of my variant, and am open to suggestions on “tweaking” it or just over what does/does not work.
    An Example using same code as Author:
    if (x == y)
    {
       x++;
       foo();
       }
    else
    {
       x--;
       bar();
       }

    My reasoning being:

    1) As I skim down between blocks after writing (a function|many if/else if statements|my project), the opening brace implies a closing brace; anything at the same indent level cannot be within that block.

    2) While within a block, the closing brace being flush with the current text implies end of (block|function|etc).

    3) Since closing brace is flush, it takes less “mental effort” to distinguish it as end of block.

    4) Removes clutter from Left Hand Side of blocks, and new blocks immediately follow the whitespace.

    5) Most importantly (on an individual level), it just feels right to both write and review. (yes, I’ve tried “Allman Vanilla” and several other styles above.)

    Note: for 1): though technically the next line indent implies start of block (as in regular banner), the open brace being to the right of the closing brace does not help with finding missing pairs. Brace pairs being flush (Allman) makes things appear cluttered to my ADHD mind.

    Reply  |  Quote
  70. Santi UNITED STATES Google Chrome Windows says:

    I’ve always prefered Allman even before I was aware of all the different coding styles, but I will use K&R if the content of the braces are only one line.

    Reply  |  Quote
  71. Philip CANADA Google Chrome Mac OS says:

    I prefer whitesmith. The reason why I choose this style is that it makes it allot easier to fix bugs. I can follow the code easier. There is not doubt programmers find it strange. But once you get used to it you won’t go back. K&R is too hard to follow the beginning and end of your code block. Allman is an improvement but it still suffers from some of the same problems.

    Whitesmith’s emphasis is on visual blocking. Your code will look nicer and cleaner.

    Reply  |  Quote
  72. Joe Boggs UNITED STATES Google Chrome Windows says:

    @ Matt Doar:
    ^ This is the guy you want on your team.

    Reply  |  Quote
  73. Mike Google Chrome Linux says:

    It’s like religion. No matter how much evidence is shown that the K&R believers believe in things that do not exist, it is ignored. You can check in Allman code into the repository till the cows come home. Even when it clearly looks much neater and easier to scan, they will simply not see it.
    I absolutely can not stand K&R. It’s horribly cryptic. Try reading code with long lines. It’s really awful.

    Reply  |  Quote
  74. Pvblivs UNITED STATES Google Chrome Windows says:

    My own code most closely resembles Whitesmith (but actual code line are indented one more space than the braces.)

    K & R got a lot of things right. But I don’t like their indentation style. As for the statement I have seen that they were the original: Yes, they were. But, as I understand it, ANSI function definitions are preferred to K & R style functions as well.

    Reply  |  Quote
  75. Joe Koder UNITED STATES Google Chrome Windows says:

    Everyone knows the only true and correct style is Whitesmith. Any other discussion is pointless.

    Reply  |  Quote
  76. Pingback: Programlamada Parantez Stilleri « Murat Çileli WordPress

  77. Pino CHINA Mozilla Firefox Fedora Linux says:

    what`s the difference between Allman & horstman?

    Reply  |  Quote
  78. Kazriko UNITED STATES Google Chrome Linux says:

    If I’m working in someone else’s repository, I’ll follow their conventions.

    However, in every project that I’m maintaining, I keep it strictly Whitesmith. There are many reasons, but the two that stand out above all others is that semantically, when you do a single statement after an if statement, you’re indenting it. Since braces are simply a way to put multiple statements where you would otherwise have a single statement, the best level for them to be is the same level that the statement they’re replacing would be at. Putting them at the level of the prior statement is misunderstanding the fundamental structure of the programming language. The other reason is that as a Python programmer, the blocking of Whitesmith makes the most sense and is the most like python, aside from Pico or Lisp style.

    As for the other brace styles, I’m OK with using GNU and Allman, even though they’re obviously misguided. ;) Banner and Pico aren’t great, but I’d take them over K&R. If there’s a library that I’m using that I need to make edits to and contribute them upstream, if it’s K&R I might seriously consider rewriting the library myself instead.

    I find it disturbing that most examples I see in other braced languages tend towards K&R format. It’s especially distressing in Rust-lang since I’m starting to do more in that.

    Reply  |  Quote
  79. Tim Google Chrome FreeBSD says:

    @ Mike:

    I don’t agree that Allman is a good indentation style at all. It is very verbose, and distracting. It’s really hard to see the logic of a function that takes more than a few lines to see, and Allman has a way of making 20 lines become over 100 easily.

    K&R is also much too verbose, at least if it uses a separate line for each closing brace, and it doesn’t seem internally consistent.

    Not even a fan of Python per-se, but any style that looks goofy when the braces are removed is clunky to me. For C style syntaxes I only like Lisp-style indentation (but with spaces separating the semicolons), so pico for me, by far.

    Then again, I loathe curly brace syntaxes and would rather see anything else short of Pascal-style syntax instead (Miranda, ML, Prolog, Lisp, Miranda, Smalltalk, etc….). Maybe I’m weird, but I think as people learn more non-C, Pascal or Basic inspired languages, the popularity of Allman will substantially decrease.

    Reply  |  Quote
  80. Ric Werme UNITED STATES Mozilla Firefox Linux says:

    @ Pino:

    Horstman has a line of code along with the open brace. Took me a few seconds to see it myself…. Abomination.

    K&R forever (except when my employer demands Allman).

    Or Python where possible. :-)

    Reply  |  Quote
  81. Kukobar MEXICO Google Chrome Windows says:

    Allman hands down.

    Code should be clean and easy to read, If code would only be relevant to a single person then all this shitty messy styles would be okay, but that’s far from the truth.

    I hate working with people that write code as fast as they can, without thinking who might read their hieroglyphs other than themselves,

    An example a successfull Allman’s style C++ beast, is Unreal4, they have a very strict convention that makes contributing to the source a pleasure.

    Reply  |  Quote
  82. Georg AUSTRIA Mozilla Firefox Windows says:

    YES, ALLMAN style forever! The one and only!

    I even do in big SQL Statements or arithmetic Formulas !

    I cringe up to today when I see the opening bracket right beneath the statement. I hate that style.
    I can not understand how software engineers, who are supposed to work properly and thoughtful, ever can do this.

    Reply  |  Quote
  83. Georg AUSTRIA Mozilla Firefox Windows says:

    @ John Galt:

    YES, that’s a statement! 6 years ago, and I fully agree! BTW, I did Allman already 1990, on the small screens. It’s simply the best to read and understand. I even tend to think that K&R people are confused in their heads, too … ;) Your code should be “good” and “proper”, and Allmann style emphasizes that.

    Reply  |  Quote
  84. John UNITED STATES Mozilla Firefox Mac OS says:

    None of the above. I hate the K&R “} else {” construct, b/c I frequently comment the start of my if/else blocks. But on the other hand, putting the curly brace below the construct statement like Allman seems like a waste of a line to me. It gains nothing in terms of readability, and wastes space. So, I’d say I’m mostly Allman, with the exception that I put the opening brace on the same line as the construct.

    Reply  |  Quote
  85. keystoneclimber UNITED STATES Mozilla Firefox Windows says:

    None of them. Use a language that didn’t forget to include endif statements or provides control flow via strict indentation of constructs. (and preferably is intelligent enough to use carriage returns as line endings rather than semicolons)

    Reply  |  Quote
  86. Jose FRANCE Google Chrome Windows says:

    I prefer K&R or pico.

    As for allman: why do you need all these blank lines around a simple else statement, is “else” so tricky ?

    I prefer to keep control on blank lines in order to use them as separators between logically distinct parts or around an especially important statement.

    Reply  |  Quote
  87. Ralf GERMANY Safari Mac OS says:

    I started with K&R and said Allman is ugly. Then I tried Allman and now K&R is ugly for me. Use a style for a while and it becomes your style.
    K&R is nice compact, but Allman is better to read. If you read your code after 1 year, readability is important, not a compactness.

    Reply  |  Quote
  88. @ Tino:
    “They knew what they were doing”.

    Yeah, and they probably had to work with tiny green phosphor CRT screens where you couldn’t afford to waste any screen real estate. But this is 2016, and we all get to work with big LCD displays with millions of pixels, so the “more compact” argument doesn’t hold water.

    And I don’t buy the habit argument either. Having braces aligned vertically *does* make it faster to quickly spot blocks, and plays nice with folding editors.

    Allman FTW.

    Reply  |  Quote
  89. Miikka FINLAND Mozilla Firefox Ubuntu Linux says:

    I changed into Horstman a while ago. It just is the best. I usually use K&R and the reason is the readability. The problem is that I miss 2 chars at a line, so because I use 8 spaces as indent, the 2 chars are quite important. It also enhances the readability. Allman in my opinion don’t enhance it. You need to move more your eyes while reading. That why the lines should be around 80-100 wide because you don’t need to move your eyes so much (and the terminal limitation). If I have too much whitespace in a function, I need to move my eyes even more and it hurts my delecate eyeballs.

    Reply  |  Quote
  90. L. Craft UNITED STATES Mozilla Firefox Windows says:

    @ Philip:
    I definitely agree; who wants sharp-edged brackets; you might stab yourself on them

    Reply  |  Quote
  91. K&R is ugly, with all due respect to the Old Ones. It’s madness for the braces to not line up.

    I’ve been using Horstmann for 25 years. Why waste an extra line with Allman? Screen real estate is a scarce resource.

    Reply  |  Quote
  92. @ Pino:
    Allman wastes an extra line after the opening brace.

    Reply  |  Quote
  93. Wandi INDONESIA Google Chrome Windows says:

    i’m choosing allman style, because that made me easier to find where opening brackets and closing brackets . although that might create more unneeded spaces, but at least I can read it more easier

    Reply  |  Quote
  94. Photuris Google Chrome Windows says:

    Does this style have a name?…

    if (x == y) {
        x++;
        foo();
    }
    else {
        x–;
        bar();
    }

    It’s somewhat compact like K&R, but makes it easy to isolate (comment or delete) a block like Allman, and also adds a bit of vertical space between blocks, making it easy to visually parse, but not as wastefully as Allman, IMO.

    Reply  |  Quote
  95. Joaquin UNITED STATES Google Chrome Windows says:

    I started with Allman (a.k.a. noob style) but after 10 years finally saw the wisdom of K&R. You get compact code without sacrificing readability. Those guys seriously knew what they were doing.

    Reply  |  Quote
  96. Ramón UNITED STATES Google Chrome Mac OS says:

    I thought I was reading YouTube comments for a minute here. “Hate”, “should be shot”, the singling out of “those K&R people.” I’d imagine it’s all in fun, though. But this discussion would never happen among languages with (1) terminal ends or (2) indentation. We’d get a little bit, I guess with (3) parentheses-style languages. The conclusion here is probably that the choice of curly braces is a bad language design choice. If it were a good choice, how could there be so much righteousness among the small vocal minorities in each camp? Seriously, “listen to the pros and use Allman braces”? What pros?!?!?! The designers of Go, Rust, Scala, Ceylon, Kotlin, and Swift? Those all go K & R. C# is the outlier.

    Personally I’d go with K & R because I have this feeling that the way you write your code should reflect its syntactic structure as much as possible. And you know what? There’s no ELSE STATEMENT in the grammar of C, Java, Rust, Swift, or Go. Nope. Just an IF STATEMENT. Cuddling the `else` reflects the syntax and semantics of the code precisely. If you want to argue what is “proper” I believe you can make the best case for K&R with cuddled elses being the most “proper.” That’s what you see in the modern curly brace languages.

    Then again, there will be those that disagree and say “oh those are just elitist language designers.”

    I’m not saying any style is “proper.” They will all compile. And some of us (me included) will have negative visceral reactions to Allman, and others will have visceral negative reactions to K&R. People are different.

    Curly braces are a bad choice that persist because we got used to them. I suppose the alternatives have their faults, too, right? Python code kind of makes you think there’s an ELSE statement, too, right? Maybe the Ruby/Ada/Fortran is best after all. But not bash, because “fi” is a weird word.

    Oh, well, continue the arguments….

    Reply  |  Quote
  97. Salvatore Mozilla Firefox Windows says:

    I started off with K&R back at uni, but I must admit that it felt a bit as if I was driving different cars where the controls are in different places in each model.

    I am now a keen supporter of the ALLMAN style.

    OK – so I would agree that Allman forces methods to become longer, but that is not at all an issue if good engineering practices are followed, which ensure that methods have clear and concise responsibilities. In doing so methods also become smaller, and the extra lines added by opening and closing brackets become irrelevant.

    What I really like of the Allman style is its clarity. Here’s my perception of it:

    The position of opening and closing brackets on a line of their own prompts an immediate understanding of what code belongs to what logical block. On the other hand, K&R only relies on indentation, which is often insufficient and creates visual strain, this being rather unwelcome if working under pressure or being particularly tired at the end of a long day. Also, the K&R style is often also seen to compress lines of code together, which ends up looking like a tin of sardines. I figure that K&R supporters would argue that Allman looks like a football pitch, but there again, when you are under stress (or perhaps just to avoid getting stressed unnecessarily) which type of space would you rather go for? In my understanding, a spacious and visually comfortable space is preferable.

    I also found that the Allman style lets you create mental images of the logical blocks of code with little or no effort (no other styles lets you do this, perhaps with the exception of GNU, which is very similar to Allman). This is almost as if code was embedded in a box, with smaller boxes for each subsequent set of brackets. So, imagine you are inspecting old code, or otherwise code that you have not originally created… a neat style will allow you to browse through the code effortlessly without having to consume extra energy trying to identify where the bits that you want are. It would then become much easier to browse quickly a chunk of code, then return to the points of greater interest for a deeper inspection.
    Of course, this requires more than just Allman, but think of it this way: Coding style is not just a style. It is a mindset!! Allman requires of you to think orderly about your code, and hopefully that will be reflected throughout much of the code that you write.

    Finally, we should also think about the style we choose beyond personal preference, by assessing what works best to achieve what we require out of every working day for years to come. I do not intend to make a comparison of styles here (this post would become a small book if I did), but there again, please go for what you think gives you the best level of effectiveness, as opposed to simply having adopted one style and never questioned it.

    Reply  |  Quote
  98. I am soo glad I found this post. I have struggled with various indentation styles for years and always come back to Allman. This is how I was originally taught, and even though I have tried to get my head around other more compact styles (K&R), Allman seems to naturally ‘sit’ better with my brain. Thanks for the voting tally. I am glad to see I am not the only one who prefers Allman. Indentation styles seem to stir a passion with programmers so it is easy to get sold on another style that just does not ‘look right’

    Reply  |  Quote
  99. hevangel Mozilla Firefox Windows says:

    It is funny that all those who support Allman, their only argument against K&R is K&R is ugly.
    Beauty is in the eye of beholder. Merely saying another style (not your style) is ugly or hard to read is not a valid reason, it’s a subjective opinion.

    On the other hand, the K&R has a reasonable argument against Allman, Allman abuse the use of whitespaces.

    I am half K&R and half pico, depends on how deep is the nest. I have no problem reading Allman though.

    Reply  |  Quote
  100. Robert Wood UNITED KINGDOM Mozilla Firefox Linux says:

    Whitesmith is easily the most readable to my eyes. Allman is OK, but a bit messier. Quite why anyone would not want to line up the curly bracket with the code is beyond me.

    K&R and GNU styles are beyond bizarre.

    Reply  |  Quote

Leave a Reply

Your email address will not be published. Required fields are marked *