How far can I refactor someone else's code?
I see a lot of edits in queue where some well-meaning user attempts to fix OP's code. They range from minor syntax corrections, to near total rewrites.
When is it appropriate to accept or reject these edits?
Here are my thoughts:
- Never edit OP's code no matter how wrong it is, unless it is strictly to increase readability, and doesn't change how the code actually works. The very question itself might be solved by pointing out the error that you are fixing, no matter how small, so don't remove or correct it in the original post.
- Only edit code for obvious typos or mistakes by the author, do not attempt to "improve" the author's code. Even if the author is suggesting something stupid or dangerous, like forgetting to escape data for a database INSERT, it's better to leave a comment and let the author correct it. Downvote if applicable.
Editing the non-code parts of a post for grammar and the like are usually not going to change what the author intended to say very much, but code is taken literally, even a very minor edit will make a huge difference.
Am I close to the mark, or way off? Is there anything else to take into consideration? What are the exceptions, if any? I'm seeing a ton of these in the suggested edit queue.
When is it appropriate to edit someone else's code, and how should we deal with these suggestions from other users?
In addition (maybe a separate question), what can I do to help educate users who suggest unwelcome edits in general? Is there any way to leave them a comment so they can understand why the edit was rejected, so they don't continue to suggest more edits of a similar nature?*
* An @ comment will notify the editor, this is clearly documented here: How do comment @replies work? *
* However, it's not clear if @ replies ping the author of a rejected edit...