3

Sometimes I see code like this on Stackoverflow:

int main()
{
if(true){
return 0;
}
else{
return 1;
}
while(true){return -1;}
}

I will usually suggest this edit:

int main()
{
    if(true){
        return 0;
    }
    else{
        return 1;
    }
    while(true){return -1;}
}

I feel like not using spaces before and after brackets is OP's style, and should be respected. Indention however should be mandatory.

My edit was followed by another edit from a user:

int main()
{
    if(true)
    {
        return 0;
    }
    else {
        return 1;
    }
    while(true) { return -1; }
}

Should I've done this in the first place? I find it more readable the latter way, but OP may not be happy about it.

Of course it is nitpicking what I do now, but what about if the post is edited again in this way:

int main( ) {
    if( true ) {
        return 0;
    } else {
        return 1;
    }
    while( true ) { 
        return -1;
    }
}

Is this tolerable? My question is: should the formatting style be mimicked when editing posts? If so, what parts should be mimicked?

4
  • 3
    Dont overthink this. Use one consistent style, and if it turns out readable, great. If not, make changes again. The second edit should ideally not have been done, as it is trivial.
    – asheeshr
    Aug 20, 2013 at 14:28
  • 1
    Personally, I never change from K&R style to C# style (etc.) or vice versa. I'm also glad Markdown doesn't make a distinction between spaces and tabs.
    – mmyers
    Aug 20, 2013 at 15:44
  • 2
    Whichever style you use, your likely to annoy someone. Just adding the indentation is the least bad option.
    – parkydr
    Aug 20, 2013 at 16:31
  • Indentation it is, I won't change the style. (no-one should)
    – FalconC
    Aug 20, 2013 at 17:15

1 Answer 1

1

I dislike the original style. The only people that use this style are newcomers to C family of languages programming, and it's difficult for the veterans to read.

I'm not particular about which style is chosen to replace it, although there are accepted conventions that can be used. If you're programming in Javascript, it almost certainly should be style 2, because that's pretty much what everyone uses. If you're programming in C#, it should be style 3.

But once reformatting occurs, changing it again is going to produce diminishing returns, and the one thing you don't want to do is get into an edit war over brace style.

Note that users with editing privileges get a little more leeway than those making suggested edits, because suggested editors are asking for time from the community to review their edits, so their edits are required to be more substantial than just changing the brace style from K&R to Allman.

1
  • From now I'll edit the code like in codeblock 3. Readable for everyone and respecting OP's brace style.
    – FalconC
    Aug 20, 2013 at 17:18

Not the answer you're looking for? Browse other questions tagged .