Just wondering what the general consensus is with things like this (as an example)...which is preferred in terms of layout/readability? I usually go with the first one.
I prefer the first because the braces match up and you can easily see which scope is ending, which code belongs to what scope, etc. and it also gives some spacing in there so you can more easily separate code from condition.
The second makes it very very hard to tell with complex program scope structures.
The problem is that there are some well-known programmers that use the second style of coding which is very bad. And newcommers repeat this bad style very othen after these well-known programmers.
I advice to use the first style of programming. it makes much easy reading of code.
What is important is consistency - a code base should choose one indent style, and use it everywhere. Typically, the choice of indent style is not a decision made by each programmer independently. And the same programmer could be using different styles for different programs - for instance, BSD KNF for kernel code, and Allman (aka ANSI/ISO/BSD) for userland code.
The problem is that there are some well-known programmers that use the second style of coding which is very bad.
Why is it 'very bad'? Surely it is down to personal preference?
The key is to be consistent. Pick a style and stick with it. Or if you are joining an established team of developers working on the same product, adopt their style to ensure consistency and readability.
I prefer the first because the braces match up and you can easily see which scope is ending, which code belongs to what scope, etc. and it also gives some spacing in there so you can more easily separate code from condition.
The second makes it very very hard to tell with complex program scope structures.
Odd, I use the second style for the exact same reason. If I see a '}', I scroll up and see what word is at the same indentation. I know the word I find will be followed by a '{', so I don't see the point of being able to have it there visibly.
If I see a '{' at the same indentation, I'll expect it to be a purely data-wise encapsulation (in a long function when I want stack variables to destruct when no longer needed).