0

Is there a standard/preferred/approved way to format the indentation/placement of curly braces ("{}") in code on SE sites (SO, SU, ...) ?

More precisely, I'm talking about the placement of the opening bracket/brace in, for example, function definitions, and if statements.

Like this:

function somefunction()
{
    // Code here
}

or like this:

function somefunction(){
    // Code here
}

I was looking at this answer: Modern HTML5 Techniques for changing classes - Change an element's class...,

and something in the comments prompted me to look at the revision history for the answer.

While unrelated to what I wanted to see, I noticed that the most recent edit to the answer was only to change the answer's example code, in a few places, from something like this:

function changeClass()
{
    // Code examples from above
}

to this:

function changeClass(){
    // Code examples from above
}

Is this an appropriate edit?

I mean, the code was fine before the edit, and, it was just fine after the edit, basically nothing different. The editor just replaced one standard code formatting method that is preferred (well, at least chosen) by the original author, with another standard code formatting method that the editor happen to prefer.

I don't think this is an appropriate edit. Since the edit was approved, and the original author, if they were aware of the edit, didn't roll it back (possibly they didn't want to participate in an edit war), so I left the edit in place, even though I thought it shouldn't have been approved.

Perhaps, if there were other significant changes that the editor could have made, and they made those changes at the same time, it would be more justified (well, I'm still not convinced the braces edit would be okay, even then).

My reasoning, is that first, it's just too trivial. The only thing added was 3 newlines, and some spaces (of course that is the nature of an edit that modifies formatting). Second, I view it as just a personal preference, neither way is particularly more right, or wrong than the other.

And, perhaps more importantly, it could lead to a user editing hundreds and hundreds of questions and answers, making only these type of changes. And worse yet, another user might edit the Q/A's again to return the posts to their preference.

Unless, of course, if there is some SE convention that one way is correct/preferred?

I understand that except for the potential for an edit war, this is not an extremely important issue. Am I on the right track, or am I making too much of this?

Note: I realize that this is mostly a computer code related question and is perhaps better suited to relevant sites, but there are many SE sites related to computer code, and I thought it was best to not potentially duplicate this on multiple other SE meta sites.

1
  • Thanks! I did a search to find an existing answer first, but my search fu is apparently lacking. Commented Oct 13, 2018 at 6:55

0

Browse other questions tagged .