7

I recently asked a Java question and my usual coding style of:

class classname
{
}

was reformatted to

class classname {
}

Why do this? And the result wasn't consistent either: At the top, my enum was reformatted to:

enum someEnumName {
    NAME1,
    NAME2
}

and elsewhere was left in this form:

enum someEnumName
{
    NAME1,
    NAME2
}

...so I'm unclear as to what the rule is in this site. One of the moderators (or whatever you call them here) was listed as having done that, but was it part of an auto-formatting tool he used?

2
  • 2
    On this site, moderators have diamond symbol near their names, like BoltClock♦ (who answered your question). Everybody else is a normal user like you. Nov 27, 2014 at 18:35
  • Before anyone comments on the dup being for answers, yes, it also applies to questions. Nov 27, 2014 at 18:41

1 Answer 1

10

The user who edited your post was not a moderator. Just a user with plenty of reputation.

According to the revisions, your original post was missing the formatting needed for your code to be correctly displayed in a code block. It should have been enough to simply add four spaces to each line to fix that particular issue, and it can easily be done by highlighting the code block(s) and clicking the "{}" editor button, or hitting Ctrl+K; I don't see why they had to go out of their way to amend your brace style either.

7
  • 3
    Although I agree it being utterly unnecessary, I see why they thought to do it. It's the "established" format of Java code and sticklers for form will always be sticklers for form.
    – J. Steen
    Nov 27, 2014 at 18:13
  • 9
    @J.Steen: And it's utterly wrong to force others code into your preferred style, regardless who endorsed it. Unless, of course, it was unformatted to begin with. Nov 27, 2014 at 18:33
  • 2
    If it's unformatted it's simple to mark-up @Deduplicator, there's no need to reformat. Calling it "wrong" is pretty strong, it's not an imprisonable offence - it could be annoying for the author. However, in the general case, if the code is unreadable then there is no other alternative but reformatting.
    – Ben
    Nov 28, 2014 at 6:14
  • @Deduplicator If it's readable code, it's unnecessary to reformat. I wasn't condoning the activity, I was merely hypothesising as to why. =)
    – J. Steen
    Nov 28, 2014 at 6:46
  • It may have been an attempt to make the code appear more compact. I tend to use that style on SO for exactly that reason, even though by habit (from employer's conventions) I use a different style. Agreed that, unless it was initially unformatted, there's no reason to edit just because of style preferences. Nov 28, 2014 at 7:29
  • @Ben: Considering that you should always leave the post in a better state after editing, and coding-style is a matter of really strong opinion, it does not qualify. Which makes it an invalid edit, due to annoying others without improving anything. (Though someone particularly annoyed would probably even call it vandalism.) Nov 28, 2014 at 20:07
  • Ok, so the long and the short of it is that there is no SO official bracketing guideline. I don't much care either way, but I do disagree on the established format for Java code. K&R bracketing has always been a dual sided religious war AFAICT in Java/C/C++ (in every place I've worked). But what confused me was the reformatting in one section and not in the other, hence my question. I'll make sure to prepend 4 spaces to the code lines in my posts, as I did above.
    – user4229245
    Nov 28, 2014 at 23:50