Comments on: The Only Correct Indent Style http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/ I will not fix your computer. Tue, 04 Aug 2020 22:34:33 +0000 hourly 1 https://wordpress.org/?v=4.7.26 By: Pierre Clouthier http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/comment-page-2/#comment-301084 Tue, 04 Aug 2020 22:34:33 +0000 http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-301084

@ Joaquin:
Horstmann compacts the code.

Reply  |  Quote
]]>
By: Mike http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/comment-page-2/#comment-300758 Mon, 06 Mar 2017 18:56:39 +0000 http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-300758

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
]]>
By: Kukobar http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/comment-page-2/#comment-300646 Wed, 17 Aug 2016 01:30:29 +0000 http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-300646

@ 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
]]>
By: Kukobar http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/comment-page-2/#comment-300647 Wed, 17 Aug 2016 01:30:29 +0000 http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-300647

@ 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
]]>
By: Robert Wood http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-300637 Fri, 29 Jul 2016 09:28:46 +0000 http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-300637

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
]]>
By: hevangel http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-300612 Sat, 02 Jul 2016 06:42:49 +0000 http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-300612

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
]]>
By: Simon Bramble http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-300610 Fri, 01 Jul 2016 09:29:29 +0000 http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-300610

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
]]>
By: Salvatore http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-300606 Wed, 22 Jun 2016 17:47:04 +0000 http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-300606

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
]]>
By: Ramón http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-300599 Tue, 07 Jun 2016 02:38:55 +0000 http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-300599

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
]]>
By: Joaquin http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-300595 Sun, 22 May 2016 23:03:17 +0000 http://www.terminally-incoherent.com/blog/2009/04/10/the-only-correct-indent-style/#comment-300595

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
]]>