I've noticed that on three occasions now (1, 2, 3) people have edited my answers and removed the indentation that I had left in quotes from OP's code and in suggested replacements. One went so far as to say "fixed indentation" in the change description. I can't find any discussion in meta which deals with the subject of indentation in answers, and I find it irritating that people should consider it broken when I go to extra effort to preserve the indentation from OP's code for ease of direct comparison and copy-paste replacement.

Is there some unwritten rule that answers should minimise indentation?

• Well, at least for the first answer you have approved the edit yourself. For the third, there will be a good chance that Jamal who did the edit will place an answer here. – Heslacher May 15 '17 at 15:52
• I wouldn't take "fixed indentation" personally, I regularly say things like that, as the text box says to. "briefly explain your changes (corrected spelling, fixed grammar, improved formatting)". It's not that it's broken, it's the first word, that roughly fits, to come to mind when describing the change. – Peilonrayz May 15 '17 at 16:23
• @Peilonrayz exactly. I've used that exact wording as well, here and on SO. – Mathieu Guindon May 15 '17 at 16:25
• "Is there some unwritten rule that answers should minimise indentation?" Yes, if the code scrolls off the screen, then there's too much indentation. In your case, it looks like it just bothered someone's OCD. I could see myself making an edit like this while I was in there fixing other things. I don't cater my answers to copy-pastas, and don't assume that others do, either. – Cody Gray May 21 '17 at 11:14

There's no unwritten rule for that, no.

People (me included) edit answers to improve formatting all the time, here or anywhere else on SE - there's even incentives (imaginary Internet points!) for doing it!

If you disagree with an edit on your post, you can roll it back and, in the comment section under your answer, you can @ping the editor and explain your (very valid) reasoning.

I go to extra effort to preserve the indentation from OP's code for ease of direct comparison and copy-paste replacement.

As a moderator I have no problem with the edits themselves, but I'd have no problem with them being rolled back either - and if it ever escalates to a rollback/edit war, in such cases the original author wins as far as I'm concerned.

The editor(s) meant no harm I'm sure.

Is there some unwritten rule that answers should minimise indentation?

No, it boils down to personal preference. Personally I'd prefer minimized indentation. Most IDEs have automatic indentation when copy-pasting code so I don't see that as an issue.

For me it's easier to read if it's not indented any extra. For the same reason as question posters wouldn't post the code like this:

        StringBuilder result = new StringBuilder();
for (int i = 0; i < input.length(); i++) {
result.append(input.charAt(input.length() - i - 1));
}
return result.toString();

• But if that snippet was listed in the OP inside a void doSomething() scope, itself inside a class Foo scope, is there any harm in keeping the 2-level indent in an answer that's quoting the OP? – Mathieu Guindon May 15 '17 at 18:15
• @Mat'sMug Not necessarily harm, I just feel that it's cleaner to strip the extra indentation. – Simon Forsberg May 15 '17 at 18:17
• If it's inside a void doSomething(), it's better to include that declaration in the code snippet. Then, it won't have extra indentation in the first place, unless the code were broken up into separate code blocks by prose text. – jpaugh May 15 '17 at 19:41
• @jpaugh Although you could write the void doSomething() with 4 spaces of indentation, as it is inevitably within a class Someclass { ... }. My point is that any such indentation is not really required. – Simon Forsberg May 15 '17 at 21:47