>They are 4 of the most used coding styles.
Were. At this point it seems that only two of them are still in common use (variations of K&R and Allman) and the other two are falling from favor. At least, that's assuming you're referring to K&R, Allman, Whitesmith, and GNU. This is basically what they look like:
K&R:
Code:
#include <iostream>
int main() {
for ( int i = 0; i < 10; i++ ) {
std::cout<< i <<'\n';
}
}
Allman:
Code:
#include <iostream>
int main()
{
for ( int i = 0; i < 10; i++ )
{
std::cout<< i <<'\n';
}
}
Whitesmith:
Code:
#include <iostream>
int main()
{
for ( int i = 0; i < 10; i++ )
{
std::cout<< i <<'\n';
}
}
GNU:
Code:
#include <iostream>
int main()
{
for ( int i = 0; i < 10; i++ )
{
std::cout<< i <<'\n';
}
}
>Why they have names, I don't really know... I don't know the history.
K&R was the style used in The C Programming Language, so a whole generation of C programmers picked it up from their best (and probably only) bible on the language.
Allman was named after the guy who used it in a lot of BSD utilities, and because C programmers then liked to learn by reading the source on their system, they picked it up.
Whitesmith was named after the compiler that used the style in it's example code. I'm not sure how popular it was, but I'm guessing it had enough of a rebellious feel that the hippies picked it up.
GNU was named because it was used (almost exclusively) in Richard Stallman's code and other FSF source. You can imagine why people might pick it up, but it's awkward to use, so I think most people dropped it just as quickly.
FYI, I use a variation of K&R:
Code:
#include <iostream>
int main()
{
for ( int i = 0; i < 10; i++ ) {
std::cout<< i <<'\n';
}
}
According to my observations, programmers who started with C tend to use K&R and programmers who started with C++ tend to use Allman. I'm not sure why.