4

One thing that has really started to annoy me on StackOverflow is that literally moments after posting some code, I find that it has been edited and the indentation changed.

We've always used a style similar to Whitesmiths (as ReSharper calls it) with the braces indented along with the block contents. What I find invariably happens is that someone will edit the code so that the braces aren't indented.

I acknowledge that our style choices may not be the most popular, but it seems arrogant in the extreme for anyone to think that their style preference is somehow preferable to the original poster's. One of the things that (for me) marks out a professional is that they learn to accept that other people make different choices and those choices should be respected. I usually react to this situation not by rolling back the edit but by leaving a comment that we made a deliberate choice of style and we don't appreciate having it overridden for no reason.

How do others feel about this? I think Stack Overflow should have a guideline about this behaviour.

7
  • 2
    See also: When is it okay to edit answers for “Code Formatting?”
    – icktoofay
    Commented Jul 27, 2014 at 23:44
  • 1
    So, you are using a less popular style, but consistently. Does the change of style remove vertical scrolling? Does it shorten lines so horizontal scrolling is less needed? Does it adapt the style used in the question to the answer? If none of those, that edit looks like noise, and should have been rejected. Commented Jul 28, 2014 at 1:00
  • I'd suggest rolling it back AND leaving a comment. Just try not to be rude in the comment.
    – Kevin B
    Commented Jul 28, 2014 at 1:44
  • A feature request / solution this could be, once a user hits X rep, they have the ability to force code-only edits to be reviewed by themselves, regardless of the editor.
    – Joe
    Commented Jul 28, 2014 at 10:13
  • 3
    I have to admit, I would be tempted to edit your code in questions like this one, since I find it very difficult to read. I'm not familiar with that style, so at a glance it looks like some of the poorly-formatted code that new users tend to post. I understand how this could get annoying for you, but try to keep in mind that when people change code formatting, it's usually not malicious, they just want to ease their eye strain, which potential answerers tend to appreciate. You are of course free to roll back. Commented Dec 29, 2014 at 22:14
  • 1
    @ThisSuitIsBlackNot Look on the bright side, I could be using K&R style! But seriously, how difficult is it really to follow my indentation style? Developers ought to be able to read code that isn't formatted precisely to their preference. The reason I use that style (and have been doing since the early 1980s) is because I consider the braces are part of the block they enclose. This was a principle I learned when I studied compiler writing techniques at university, the lecturer insisted on it and it made sense so I've stuck with it.
    – Tim Long
    Commented Dec 30, 2014 at 23:38
  • It may not be arrogance - just missunderstanding. If I see indented braces in a small bit of code (not a big file where they are consistenly indented everywhere) I will simply think it is a formatting issue. Because it is really very rare. On the other hand so many questions really lack formatting. So it is easy to get confused.
    – Olga
    Commented Dec 25, 2015 at 14:08

2 Answers 2

6

Stack Overflow could add a guideline specifically about this (here for example), but the problem is enforcing it.

Many edits are made by people with lower rep who only have the capability to suggest, then the suggestion goes through a review queue where people with not much more rep review it. A lot of these people simply don't have the level of professionalism you talk of. These edits will invariably get accepted because there's nothing inherently wrong with them (except they annoy you).

So I wouldn't count on there being any real way to fix this issue. The way you are currently dealing with it is fine, but maybe you should start rolling the edits back? The editor won't lose any reputation they gained (if any) from the edit, but at least your post will be the way you want it.

Related: Should a rollback on a Suggested edit remove reputation points

2
  • 2
    Thanks for the feedback. I will reflect on this for a while. I don't want to start any 'edit wars' over what is a relatively trivial matter, but I will likely continue to leave comments. In fact the penultimate paragraph of my question might be a good basis for such comments.
    – Tim Long
    Commented Jul 28, 2014 at 6:58
  • @slugster Agree with the mechanics point of view, of the web site. However, I often edit code formatting, because it's sometimes horrible and makes it harder for me to either help, or try understand a solution, as well as triggering my OCD. However, I apply what in my experience is the most common used formatting, in Java, even though my own differ from that. Indents though, 4 spaces, or 2 spaces, as long as it is consistent. I like 2, but 4 is more common, so I use 4. Block start character { comes on same line after method signature, not on new line. Two examples of what I do.
    – Wrench
    Commented Mar 24, 2017 at 3:28
3

When you post questions on a public site like this, having your code formatted to a more popular style may increase the number of readers and thus increases the chance to get a good answer. You should actually be thankful for the editor helping your question to be well understood by more people.

Of course, if the new format seems to be obscure or not so popular, rolling back is best you can do. If it is unclear if the new format is really more popular (especially here on SO), keeping the original format is IMHO to prefer, of course.

it seems arrogant in the extreme for anyone to think that their style preference is somehow preferable ...

Well, I think it is at least a little bit arrogant to expect that code posted to SO is "still your code" and noone else should touch it, not even reformat it.

If you get answers for your question containing some extensions to your original code, noone forces you to keep the format of that code when integrating it into your codebase again, you can (and will) choose your preferred style of indentation.

You must log in to answer this question.

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