The guys that wrote Doom 3, the source code to which has been proclaimed to be the most readable that has ever been written, use that style of bracketing. Not a problem for me, better than the other methods to some.
That is actually a very common style and a lot of people prefer it over other common styles. I have actually been debating on switching to K&R from my usual Allman style because of how many lines it can save you.
It's a personal style only. When I contribute to a project, I'll format using astyle, beautifier, or similar so people won't complain.
Some projects even have specifications as to how a certain piece of code should be formatted and provide commands to do it automatically using tools like stated above.
It depends on the project. I wouldn't say there is a most common style. Usually in the beginning the project lead's will set out some guidelines on what formatting the project will use, how the documentation will be done, ect.
The general thing is they want everyone to be using the same formatting on the project because it increases readability.
some people code like this, and it bugs the sh!t out of me when I want to read it. Especially on this website.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <stdio.h>
#include <stdlib.h>
int main(){
while(true)
{
int upper_bound = 1+ rand()%31;
while( upper_bound <= 32 ){
int sum = 0;
for(int i = 1; i <= upper_bound; i++){
sum += i;
}
printf("upper_bound = %d\nsum= %d\n", upper_bound, sum);
upper_bound++;
}
}
return 0;
}
Yeah, I coded that myself just to proof how bad of a style that can be especially without indentinng. I code like this, its called discipline and knowing how to use an ide.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int main()
{
int a = 10, b = 2;
int temp = 0;
temp = a;
a = b;
b = temp;
if( a == 2 && b == 10 )
printf("success\n");
else
printf("failure.\n");
return ( a * b );
}