45

I met many questions/answers which look like this:

questions/answers using unnecessary indentation

Should I improve the formatting of those questions/answers?

7
  • 41
    Be careful with questions though. If the question was tagged python, the problem may be caused by the indentation and changing it would then invalidate the question. Commented Jun 13, 2016 at 8:55
  •     And what about paragraph indentation that some people seem to be using in their answers?
    – CodeCaster
    Commented Jun 13, 2016 at 10:30
  • The question was about HTML, not about Python. Commented Jun 14, 2016 at 14:33
  • 4
    @AmedeeVanGasse It's about unnecessary indentation, not about a specific language.
    – Minh Tri
    Commented Jun 14, 2016 at 14:49
  • I agree with your accepted answer, that an improvement to the indentation is generally a good thing. However your question falls foul of another rule, which is never to post code or data as an image
    – Borodin
    Commented Jun 14, 2016 at 18:33
  • Related: meta.stackoverflow.com/questions/304072/…
    – DavidG
    Commented Jun 15, 2016 at 0:44
  • 2
    @Borodin in this case, perhaps using an image is a good idea, lest some do-gooder comes along and tidies up Dan's code formatting...
    – seanf
    Commented Jun 15, 2016 at 9:41

2 Answers 2

64

Yes, please. That would make the code a lot easier to read. But make sure you improve other things in the post (grammar, capitalization, tags) as well. As your edits still go through the review queue, you should make sure you don't waste reviewers' time.

5
  • 6
    What is the advice if the only problem with the post is the indentation?
    – Blackwood
    Commented Jun 13, 2016 at 3:21
  • 9
    @Blackwood if editor is over 3K (like you) go ahead and fix indentation to be consistent. Make sure not to re-edit to style you like (check previous edits to avoid edit wars). Commented Jun 13, 2016 at 4:05
  • 11
    To fix the problem of opinionated indentation style for HTML, CSS and JS, do this: Put the thing in a stack snippet, press the tidy button, add it to post and remove the beign:snippet and end:snippet comments to make it a code block preserving Stack Overflow's built in indentation ;) It sounds like a long process but only takes few seconds.
    – T J
    Commented Jun 13, 2016 at 9:07
  • 2
    @TJ Yeah, but keep in mind that "Tidy" has bugs. See my two bug reports here and here.
    – Mr Lister
    Commented Jun 14, 2016 at 14:37
  • I disagree. Aren't reviewers wasting the editors time, if they reject a useful indentation edit? Indentation is mostly crucial for readability of code!
    – csabinho
    Commented Oct 11, 2019 at 21:49
12

If there exists indention, but it is slightly weird, as in this case, you could edit the post and make the indention sane.

Though most of the time this is caused by beginners who indent with tab key, but haven't configured their editor to correctly insert spaces. In that case you aren't really doing them a favour by silently fixing the indention. It might be better to just leave a comment and point out this problem to them and have them fix it themselves.

As for posts where the indention is completely haywire, or entirely missing, then that's just plain rude to the people reading. In such cases, please don't edit the post and fix the indention for them, you are just "giving them fish" and encouraging them to come back with more utter crap questions. Leave a comment and prompt the OP to fix it themselves. Tell them how code formatting works if they have failed to grasp that part. Refuse to read or answer the question until they have fixed it. A down vote until they fix it might be good too.

9
  • 4
    This completely make sense but the problem is that most questions/answers of this type (I think) belong to newbies who create a throwaway account just to ask/answer a particular question. But I will keep your advice in mind.
    – Minh Tri
    Commented Jun 13, 2016 at 9:13
  • 5
    @Dan If everyone refuses to read the crappy code until the OP have been bothered to fix indention, this wouldn't be a problem. The core problem is really the "helpful" people encouraging people to post complete crap by spoon-feeding them with complete code formatting edits.
    – Lundin
    Commented Jun 13, 2016 at 9:22
  • When a question is edited, the OP gets a notification about it. That is just as good as adding a comment, and it doesn't add clutter for anyone else. When you add a comment and the OP reformats, will you always delete your now irrelevant comment? Congrats if you do, but most people don't. Commented Jun 14, 2016 at 14:38
  • 1
    @AmedeeVanGasse The difference is, if you don't fix the indention you tell the OP: "posting crap is not ok here". If you do, you tell the OP: "don't bother with fixing your indention ever, have some other fool do it for you". Outdated comments is not a big issue - comments are not important, they are not really site content. A wall of unindented crap however, is a severe issue.
    – Lundin
    Commented Jun 14, 2016 at 14:45
  • I am glad that we both agree that a wall of unindented crap is a severe issue. Feel free to call me a fool, but with my OCD can't tolerate that crap to be online any longer than it has to be. Commented Jun 14, 2016 at 14:52
  • 1
    Honestly, when starting here, learning how to handle the indentation/code system is extra load. Having your code edited to look pretty tells the poster how to make code pretty. Commented Jun 14, 2016 at 17:58
  • @AmedeeVanGasse I once made a suggestion that we should make unindented code a valid reason to close the post, but it got down-voted to meta hell. The crap huggers won, so the solution that SO wants is apparently not to remove the crap, but to embrace it and encourage it. The truth is though, you'll never get rid of these problems unless you address the root cause. No amount of editing will stop the crap from re-appearing. It must be closed, deleted or prevented from entering the site in the first place.
    – Lundin
    Commented Jun 15, 2016 at 6:44
  • Let's agree that unindented crap is a severe issue, and agree to disagree on the methods to prevent or cure it, shall we? :) Commented Jun 15, 2016 at 6:49
  • how exactly should you fix indentation? It's all manual? It gets really annoying when you have code, then added some other code in your editor, then you hit cmmd + k to make them all into one code, but the editor indents the previous code snippet so it can include the new code as well. Is there any fix for that?
    – mfaani
    Commented Dec 1, 2016 at 16:04

You must log in to answer this question.

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