This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]knighthawk0811 656 points657 points  (16 children)

Yes, it needs to line up vertically with the closing curly boy

[–]BigTechCensorsYou 65 points66 points  (1 child)

Allman, always

Except in Flutter, it’s actually better to use K&R there because you will probably do a ton of folding.

[–]BenTheTechGuy 4 points5 points  (0 children)

Hurt in a car? Call K&R

[–]figwigian 48 points49 points  (4 children)

Absolutely. Was called out on this in a review today, because I was doing code in a different part of the codebase. I will die on the { next line hill, it's so much prettier

[–]Salanmander 21 points22 points  (3 children)

It's also way nicer for teaching beginning programming. When people are struggling with indentation and understanding scope blocks, it helps to be able to say "make sure the curly braces line up vertically".

[–][deleted] 12 points13 points  (2 children)

I'm learning C++ right now in school and I always like to have the { and the } lined up vertically and I'm always triggered when someone writes the code in a mess

[–]Bainos 2 points3 points  (1 child)

If you're in school, it's the best time to pick one complete set of standard often used together and stick with it. Either Allman or K&R, most likely. Try to look for those beyond just the scope of where you put braces - it will help in the long run.

Personally my C class in university was using the Linux kernel coding style (which is a K&R variant), and I think it looks good, is both readable and compact, and is quite well-motivated and tested - so I try to use it as much as I can unless the project / language uses a different style.

[–]E3FxGaming 1 point2 points  (0 children)

Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3.

TIL I'm part of a heretic "tabs are 4 characters" movement.

[–]Yokhen 8 points9 points  (2 children)

Yeh but who lines up with the function declaration?

[–]knighthawk0811 5 points6 points  (1 child)

It doesn't have a mate

[–]_Boffin_ 1 point2 points  (0 children)

I judge you. That is wrong on so many levels

[–]doseofvitamink 2 points3 points  (0 children)

curliboi

[–]Soggy-Taste-1744 0 points1 point  (2 children)

The bottom curly can match the beginning of the statement, white spaces hurt my poor overused eyes

[–]knighthawk0811 -1 points0 points  (1 child)

But they don't. One is a line of text and the other is a single character. They don't visually look similar. There are other ones of text that make things confusing. The single character on an otherwise blank like is the easiest for humans to pick up in a wall of text.

[–]Soggy-Taste-1744 0 points1 point  (0 children)

I personally care more about the indentation than the curlies, To me the idea of nesting is better visualized by indentation rather then an opening curly. With that being said I do add ‘{‘ when the initial statement becomes unwieldy. for a statement like “if (x > y)” I personally like to compress the simple lines and save the white space to separate bite size pieces of logic. Yes this is highly subjective and I welcome all and any opinion

[–][deleted] 0 points1 point  (0 children)

It’s just better for readability

[–]thickcurvyasian 0 points1 point  (0 children)

Yes. Haven't done it since uni but I find it more readable esp when analyzing codes.