11
\$\begingroup\$

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?

\$\endgroup\$
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Heslacher May 15 '17 at 15:52
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – Peilonrayz May 15 '17 at 16:23
  • \$\begingroup\$ @Peilonrayz exactly. I've used that exact wording as well, here and on SO. \$\endgroup\$ – Mathieu Guindon May 15 '17 at 16:25
  • 1
    \$\begingroup\$ "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. \$\endgroup\$ – Cody Gray May 21 '17 at 11:14
10
\$\begingroup\$

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.

\$\endgroup\$
5
\$\begingroup\$

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();
\$\endgroup\$
  • 1
    \$\begingroup\$ 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? \$\endgroup\$ – Mathieu Guindon May 15 '17 at 18:15
  • 6
    \$\begingroup\$ @Mat'sMug Not necessarily harm, I just feel that it's cleaner to strip the extra indentation. \$\endgroup\$ – Simon Forsberg May 15 '17 at 18:17
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – jpaugh May 15 '17 at 19:41
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – Simon Forsberg May 15 '17 at 21:47

You must log in to answer this question.

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