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(); 
    }
{democracy:21}

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 programming and tagged . Bookmark the permalink.



104 Responses to The Only Correct Indent Style

  1. Kukobar MEXICO Google Chrome Windows says:

    @ hevangel: is not about ugliness, is about readability. Allman style has line spaces BUILTIN – that makes it easier for the eye – this is important when a lot of people work with each other’s code. I would be surprised if you never leave any blank line between statements either. If that’s the case, you might consider switching to a LISP language altogether *jiggles*

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

    @ hevangel: is not about ugliness, is about readability. Allman style has line spaces BUILTIN – that makes it easier for the eye – this is important when a lot of people work with each other’s code. I would be surprised if you never leave any blank line between statements either. If that’s the case, you might consider switching to a LISP language altogether *jiggles*

    Reply  |  Quote
  3. Mike Google Chrome Linux says:

    I’m a Java developer and it irritates me to no end to see all the other developers so religiously cling to the annoying and cluttery K&R style. I can identify code much quicker with Allman style. With K&R you can’t trust if an indent is because of a wrap, and you have to scan your eyes to the right. Braces don’t line up with K&R. I can’t for the life of me understand why anyone thinks that K&R is better in any way shape or form. Sure, you “save” a line. But you’re not saving any time, at all, whatever, clumping code together like goo using K&R.

    Reply  |  Quote
  4. Pierre Clouthier CANADA Google Chrome Mac OS says:

    @ Joaquin:
    Horstmann compacts the code.

    Reply  |  Quote

Leave a Reply

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