views:

418

answers:

10

No holy wars please - (ultimately a standardised and consistently-observed house-style on a project always wins out whatever is chosen), but I am genuinely interested in the preferences of people for K&R style formatting:

public bool CompareObjects(object first, object second) {
    if (first == second) {
        return true;
    } else {
        return false;
    }
}

over BSD style:

public bool CompareObjects(object first, object second)
{
    if (first == second)
    {
        return true;
    }
    else
    {
        return false;
    }
}

K&R seems to be making a bit of a comeback recently (I'm an old programmer, so I've seen these things fluctuate); do people think K&R looks more professional, more cool, more readable, is compactness when viewing more important than extending the structure down the screen?


Please use the 2 community wiki answers below to vote for K&R vs. BSD. Polls shouldn't earn rep for the first person that manages to type "BSD FTW!"

My God! This question is nearly 2 years old and people are still down-voting it; ENOUGH!

A: 

Neither wins all the time, but I personally prefer K&R. I use whatever standard either exists for the language, workplace, or is already in place for the codebase. If, for some reason, I don't like the standard in place, most IDEs can convert between two formatting styles, so I take advantage of that ability and write code in the style I like the best (which happens to be K&R), but convert it before checking in.

Thomas Owens
+1  A: 

I'm one for the BSD style.

FOR
+1  A: 

We've banned this K&R style from our projects here after we had rare and unusual but fatal showstopping bug that was caused by an inaccurate copy & paste operation by an unnamed developer in our team.

I've never liked it anyway, but after searching for weeks we found the evidence laughing in our face.

Besides, it's not more compact. It's more dense, and that's not a good thing.

Dave Van den Eynde
+1  A: 

Asked plenty of times before on SO. One example:

http://stackoverflow.com/questions/159366/is-there-a-best-coding-style-for-identations-same-line-next-line

Dana
Thanks for pointing this out.
Gordon Mackie JoanMiro
+3  A: 

I strongly prefer BSD, but I've gotten used to seeing a cross (it's pretty common in the library i'm working on)

public bool CompareObjects(object first, object second) {
    if (first == second) {
        return true;
    }
    else {
        return false;
    }
}

It took a little time to get used to, but it's nice because it saves space and clearly marks the beginning/ending lines.

chills42
I use the same style, except for adding a space after the declared function name, i.e. `public bool CompareObjects (object first, object second) {`
Lo'oris
A: 

I'm using BSD style when programming in the Microsoft ecosystem (Visual Studio preffered that style back in VC6 days) and the K&R style when programming in Java (Eclipse prefers this style)

bernhardrusch
eclipse doesn't "prefer" any style, especially not on Java code, it can be configured to format the source in any way you want.
fuzzy lollipop
A: 

I prefer K&R:

public bool CompareObjects(object first, object second) {
    if (first == second) {
        return true;
    } else {
        return false;
    }
}
Chris Marasti-Georg
+3  A: 

I prefer BSD:

public bool CompareObjects(object first, object second)
{
    if (first == second)
    {
        return true;
    }
    else
    {
        return false;
    }
}
Chris Marasti-Georg
A: 

I, too, am an old programmer (20+ years) and I have learned that the best way to write code is to write it clearly, and obviously.

That said, I prefer the BSD style with one minor alteration. I too, like compactness (too much white space annoys me) so I would change the example above to be:

if (first == second)
{   return( true ); }
else
{   return( false ); }

but if the code blocks were longer than a single line, I would go with the pure BSD style (as shown above).

Why? Because that is easier for me to read.

A: 

K&R because more code fits on my screen. I appreciate the benefits of BSD style. However, I find that more code on the screen is better for understanding/preventing errors overall.

Brian Knoblauch