43

While reviewing, I recently encounter some minor (suggested) edit cases where the codes in the questions are changed by the editor but are not part of the problems.

One instance is something like this (tagged as C#):

void static foo() {

}

Which is edited to

static void foo() {

}

And another is (also tagged as C#):

bar.tostring();

which is edited to:

bar.ToString();

It is obvious that in both cases, the editors changed the codes since otherwise they won't even compile. I understand that this could violate the question if part of the problems presented in the question is the very error which presents in the code itself (like, quite commonly, variable A does not exist in the current context).

But as I read those questions, I know that the questioners are writing those codes not for compilability, but rather just for:

  1. giving some hypothetical code examples which they could have written or
  2. giving simpler code than their own problem for the sake of giving minimal example but happen to have some typo errors

At first, I am tempted to reject the edit because I think it does not do any improvement whatsoever. But as a coder, I also know that compilability is an improvement.

What do you think we should do in such case?

1

5 Answers 5

84

If this kind of thing is found in an answer, fix it without hesitation!! I know some people are insistent upon some kind of golden rule that edits should never touch code, but that's stupid. Code isn't any more sacred than words are. The whole point of collaborative editing is that none of us is as smart as all of us. I regularly fat-finger code snippets in my answers because I type 90% of the code directly in the Stack Overflow editor, which doesn't have syntax checking (yet!). It is entirely likely that I've made a simple syntactical error, therefore preventing the code from compiling or introducing a gratuitous error that is completely irrelevant to the point and will just inhibit understanding.

On the other hand, if you see this kind of thing in a question, exercise extreme caution!! You can't always tell if this type of simple mistake could be contributing to the problem under discussion. If and only if you are an expert in the relevant language and confident that this mistake is unrelated to the problem(s) giving rise to the question should you feel free to make these types of edits to questions. Better yet, get confirmation from the person who asked the question that it was a typo. Do not "suggest" edits like these. Edit reviewers are not sufficiently qualified to assess the validity of your edits because they are not guaranteed to meet either of the criteria listed above. It's also asking too much of them.

But please don't succumb this attitude that code blocks are so sacred that we must let errors that might have crept into them fester forever. The "just leave a comment" strategy is a poor solution in general. Of course, if you're unsure about something, you should ask. But if you are sure, don't clutter up the site with comments and waste people's time asking. Just fix it.

7
  • 9
    I agree with all your points, and would like to add that if you're going through the hassle to change a post's code, update the rest of the post as well. It doesn't make sense to make one edit to the code when the whole question's grammar is messed up. Fix all of it at once, if you're able.
    – Mage Xy
    Feb 15, 2016 at 19:56
  • 1
    I may be seeing to much into the future or over-complicating this but wouldn't it be possible then to limit the code edits to people who has a certain amount of reputation on the corresponding tag?
    – jclozano
    Feb 15, 2016 at 21:29
  • 4
    @jclozano It would be possible, but I strain to see the point. Users without edit privileges have to suggest edits, which are then subject to approval by 3 trusted community members. Why restrict people from suggesting edits? If that approval process is breaking down, then we have a different problem. If you're talking about full edit privileges, the idea is that users who have earned those privileges should be trustworthy enough to exercise discretion in editing. I can fix code formatting in a Java question without knowing any Java. I wouldn't edit the code, though. Different story in C++. Feb 16, 2016 at 5:22
  • 1
    @CodyGray I agree regarding limiting the suggestion of edits, but i was thinking as an alternative, as an example: to edit without review you need 2000 reputation, i was thinking more on the line of "need 500 reputation on the tag with at least 4 answers in the same tag with 50 reputation each to enable editing on this tag"
    – jclozano
    Feb 16, 2016 at 16:02
  • 1
    You are somehow answering a different question. OP asks if he should approve certain kind of edits - not if he should edit the questions or answers himself. To what you have aswered - you have a very positive mind, but as far as I recall, most of the edits of the kind there is in question does not solve a problem in the code, but merely adds subjective opinions or errors, if not it is a edit just for the purpose of editing ...You could be right, but then we need a much higher rep for editing privileges, and not earning badges just for edting a certain number of old posts ... Feb 16, 2016 at 17:29
  • 1
    @jclozano: If we could separate code editing from other editing, maybe; I find that dubious, but eh. Since we can't, I'm gonna go ahead and say NO WAY JOSE. I can and do routinely make excellent edits that fix all kinds of things in tags I know next to nothing about on this and other sites. Most editing takes little specific technical expertise. Feb 16, 2016 at 23:16
  • 1
    Thanks, I think the key phrases here are: "Code isn't any more sacred that words are" and "if and only if you are an expert in the relevant language". ;)
    – Ian
    Feb 17, 2016 at 1:53
1

I would say yes, you should fix syntax issues in example code, as people may copy and paste (as I frequently do) without realizing it will be a problem, or will just learn it the wrong way (which may not cause a problem but may be improper or more difficult to read).

1

All code should be highlighted :) Sometime it may because of syntax errors. it's hard to read and we need to fix as soon as possible.

1
  • If it is formatting problem, I cannot but agree with you. :) but if it is syntax error, or even more subtle logical error in the code, I am just afraid that changing the code may change the meaning of the whole post.
    – Ian
    Feb 17, 2016 at 1:39
-3

Stop overthinking it. The edits are valid. End of story.

1
  • Thanks for the reply. You are right to say that the edits are valid. But the logic should be: because they are valid, it would be more probable for us to change the original problem/answer - intentionally or unintentionally. This is what makes me more careful in approving/disapproving such edits - non an overthinking actually.
    – Ian
    Feb 17, 2016 at 1:36
-14

Edits should not change any technical details in the post. If the post has void stXXXXic foo() and the OP says that getting NPE inside foo() line 79, DO NOT change the post and make it static void foo(). Always ask the OP to change it by leaving a comment.

Edits should be used to only change formatting or grammar / sentence structures and should almost always be non-technical and in case the issue is indeed linked to the typo in the code, then you could either answer it or leave a comment.

1
  • 1
    Agree to some point; in theory and in the best of all worlds CodyGray may be right, but in practice I think your approach is the best. For old questions and accepted answers it should certainly be default behavior to comment instead of editing right away. And if an edit in a review not clearly corrects a problem or error, or otherwise not is a obvious improvement of the code sample, and it is a code edit only - then dont approve the edit. If other (awake) reviewers see some magic in the edited code, then the edit is approved anyway ... Feb 16, 2016 at 17:40

You must log in to answer this question.

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