Why are certain bracket style/formats prefered in c/c++? [closed]
I've gotten the gist that the following
<T> my_function(...) {
....
}
is preferred by most, compared to:
<T> my_function(...)
{
....
}
Likewise for:
if (...) {
...
}
being preferred over
if (...)
{
...
}
Is this true and if so, why is the former style preferred over the latter?
This isn't necessarily preferred - they're different styles, and different teams have their own preferences.
Many people prefer the former because the code becomes shorter and more "concise". Many people prefer the latter because it's easier, at a glance, to see that the opening parenthesis character was put in place. However, these are both preferences, and different people prefer different things (and even different than the ones you displayed, such as using indented parens, etc).
The first one is popular mostly, because it is demanded by Sun (Now: Oracle) in Java
精彩评论