From the list below, what’s your preferred style?
I originally started with
#4, but now prefer #7
I like the braces to line up with the statements. It helps identify the end of a group. And yes I know that all modern editors will do brace matching and what not.
It’s what I was taught in college and it stuck with me.
as well for readability and long time use.
edit: and probalby due to Pascal… my first taught language…!
2 would be the Allman style
The Allman style is named after Eric Allman. It is also sometimes termed BSD style since Allman wrote many of the utilities for BSD Unix (although this should not be confused with the different "BSD KNF style"; see above).
This style puts the brace associated with a control statement on the next line, indented to the same level as the control statement. Statements within the braces are indented to the next level.
This style is similar to the standard indentation used by the Pascal languages an...
All the styles above are from the above wikipedia page
I remember having exercises where we were limited to the number of lines of code we could write… curly braces were included in the line count and they forced us to use that style. Made for some interesting solutions.
#2 - I like the block structure it provides.
Interesting posts today
@ckrusen. Thanks for sharing. I had no idea that this level of style documentation was even out there.
SHIVERS How dare you use such language here!
I’m also with using
BTW - I never liked that the closing brace of a C switch() statement didn’t line up …
// do this
// do that
// do this for 2
// do that for 2
// do alternate
When using style 7, the closing brace should be at the same indent of the line above it. And I was not going to start addinging braces to the case blocks like
// do alternate
#2 definitely for me.
I agree Calvin, lining up braces is essential for easily being able to eyeball complex nested statements (although newer IDE’s handle this for you - Epicor not so much)
@Hogardy While i started toying with Basic, Pascal was my first real language as well. Borland Delphi
/* Same Here */
Did not have a choice at that time… hey it was the 80’s ! c language was not yet isotified !
Mind you I never used Pascal during my work. I was using machine language
and C… . when I started the working world…
Pascal was the Comp-Sci 101 requirement for engineers at my college.
And that was on the original Macintosh computer.
Python FTW? Where indenting dictates the structure.
I quite like Python. It’s fun!
Same here, I was in the first year of High School programming class and it was Pascal, lead by some cantankerous teacher that didn’t really help us learn.
I am a fan of option 2 but wanted to note one option you did not include which I ban:
with or without spaces in front of the DoSomething I don’t care but it is too darned easy to try and add or remove logic around this and get some interesting bugs:
If you were clear in the initial use, you will please your future self or the axe murderer who knows your address and takes over your code in the future
GOTO in a C program?
Part of the standard or not, that’s heresy!