Indenting and brace styles

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.

1 Like

I’m a #2.
It’s what I was taught in college and it stuck with me.

4 Likes

2
as well for readability and long time use.
edit: and probalby due to Pascal… :wink: my first taught language…!

3 Likes

2 would be the Allman style

All the styles above are from the above wikipedia page

4 Likes

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.

1 Like

#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.

2 Likes

SHIVERS How dare you use such language here! :wink: :crazy_face:

I’m also with using #2

1 Like

BTW - I never liked that the closing brace of a C switch() statement didn’t line up …

switch(i){
	case 1:
		// do this
		// do that
		break;
		
	case 2:
		// do this for 2
		// do that for 2
		break;
		
	default:
		// do alternate
		break;
	}

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

	default:{
		// do alternate
		break;
		}
	}

#2 definitely for me.

May all javascript programmers who use brackets on the same line as code be strung up by their toenails :stuck_out_tongue:

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

4 Likes
Begin
   /* Same Here */
End.
1 Like

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 :tired_face: and C…:slightly_smiling_face: . when I started the working world…

Pierre

2 Likes

Pascal was the Comp-Sci 101 requirement for engineers at my college. :frowning:
And that was on the original Macintosh computer.

1 Like

Python FTW? Where indenting dictates the structure.

- Steve

3 Likes

Fixed it for ya :wink:

4 Likes

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.

1 Like

I am a fan of option 2 but wanted to note one option you did not include which I ban:

if(foo==bar)
DoSomething();

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(foo==bar)
DoSomething();
DoSomethingElse();

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

if(foo==bar)
{
DoSomething();
}

4 Likes

That was a big bug a few years ago Apple Bug
https://embeddedgurus.com/barr-code/2014/03/apples-gotofail-ssl-security-bug-was-easily-preventable/

2 Likes

is really

if(foo==bar)
DoSomething();
DoRegardless();
1 Like

GOTO in a C program?

Part of the standard or not, that’s heresy!