What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 150 Stack Exchange communities.

I frequently answer questions on the python tag and one thing that happens (all the time) is that code is not correctly indented. In python, the indenting of code blocks matters:

if foo:
elif other_foo:

is a SyntaxError. In this case, it is completely obvious that the user meant to do:

if foo:
elif other_foo:

The question isn't about getting a SyntaxError, it's about something else, so it's pretty clear that this is just a copy/paste problem and not knowing how to clearly format code on SO. Here's the question -- with the plethora of statements here on Meta about NEVER EDIT CODE IN A QUESTION, does that apply to this as well? To fix it, I would do nothing other than format the code so that it produces the behavior that is mentioned in the rest of the question.

Of course, indenting of code is just an example. mis-spelled variable names are another thing which I see occasionally.

My current policy is to leave a comment asking the OP to fix the problem. Is that the correct way to go about this, or should I edit?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

I routinely edit code for appearance only. By that I mean I won't change formatting that the user intended to have, but I will often edit a question to fix markdown problems. For example, if a "#" appears at the beginning of a line and gets turned into a headline, I'll fix that. Or if extra blank lines break a code sample up, or one line isn't indented enough and breaks a sample up, I'll fix those.

I think syntactically significant whitespace as in Python could fall under this category, but be careful. Sometimes a user's bad formatting could actually be causing the code to be misinterpreted, and you wouldn't want to accidentally change the meaning of the code.

share|improve this answer
Yeah, one ambiguity here is that you can't always tell when the block of code actually should end. (sometimes it's obvious -- other times it isn't). I wouldn't touch something if it isn't obvious. – mgilson Aug 1 '12 at 2:53
In this (unusual) case, I'd say it's ok to edit the code if it makes the code consistent with the OP's description of the symptom. – Keith Thompson Aug 1 '12 at 5:03

You must log in to answer this question.

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