136
\$\begingroup\$

Is it okay to edit the question to include the improved code?

I would like to do so for the following reasons:

  • To share the improved code with others
  • To show the answering persons that I take their feedback seriously
  • To make sure that I understood (and implement) the feedback in the right manner

I understand that the original code must remain untouched otherwise it would invalidate the question.

But how do I handle code review iterations? Do I have to create a new question for each new revision?

In my opinion, writing code is an iterative process. I ask for a review, I consider the feedback and implement it, and then what? Shall I open a new question for the next review round or is it okay to update the question with the improved code (like suggested here)?

This meta question belongs to this post.

Note: that this question has established a new/revised policy for how to edit posts after answers are received. Previous policies have been made obsolete as a result. The previous policy questions have been deleted, but, for those with enough rep, can be seen here:


Quick copy/paste link for comments:

[What you may and may not do after receiving answers](https://codereview.meta.stackexchange.com/a/1765)

\$\endgroup\$
2
  • 13
    \$\begingroup\$ Good question Joel, and good motives. This is exactly what we want to show here on the site. We need a lot more people like you here on the meta and on the main Code Review site. Thanks for sharing your questions and ideas for making Code Review a more inviting place! \$\endgroup\$
    – Malachi Mod
    Apr 15, 2014 at 13:08
  • 4
    \$\begingroup\$ Not to be confused with: A question about editing the code in someone else's question \$\endgroup\$ Apr 25, 2014 at 13:24

2 Answers 2

151
\$\begingroup\$

You have several options for follow-ups:

  1. Accepting an answer

    If one of the answers gives you good advice with clear directions for improving your code, just accept the best answer and upvote any other answers you feel were helpful. The checkmark that you confer is the best way to show appreciation on this site, as it gives 15 reputation points and raises that answer to the top, and you also earn 2 reputation points for accepting an answer. Posting your revised code would be redundant.

  2. Posting a new question

    If you incorporate advice from one or more answers, but are still unsure that the code is as good as it should be, then post a new question with your revised code. For the benefit of other users, add mutual links: mention the previous question in the new question, and add a comment on the old question linking to the follow-up question. See How to post a follow-up question

  3. Posting a self-answer

    If you want to show everyone how you improved your code, but don't want to ask another question, then post an answer to your own question. Selfie answers are acceptable on Stack Exchange sites, and even encouraged: there is a self-learner badge you can earn for that. Selfie answers can even be upvoted, downvoted, or commented on in their own right. However, your answer must meet the standards of a Code Review answer, just like any other answer:

    • Code-only answers that don't actually review the code are insufficient and are subject to deletion.
    • Describe what you changed, and why. (see above point)
    • Give credit to any other users who may have helped you. As stated in (1) above, posting a selfie that merely reiterates an existing answer without adding new insight would deprive another user of well deserved reputation. Also consider making your selfie community wiki if you feel that earning reputation from it would be unfair. However, if it's not done yourself, and a moderator determines that the self-answer is primarily dependent on other answers, then they are allowed to activate the CW status automatically.
  4. Posting on an external site

    If you are unwilling to write a sufficient explanation to constitute a good Code Review answer, then it would be best to refrain from posting your follow-up on Code Review at all. Instead, you may host your revised code on an external site (e.g. GitHub, GitHub Gist, Pastebin, JSBin, JSFiddle, Ideone, SQLFiddle, your personal blog, etc.) If your off-site host has revision capabilities, then include a link to the revision that was posted in the question. Format the edit as if it was always part of the question, and not as if it is an "Update". Something like the following:

    This code and updates are available at: [this repository](...some revision...)

    You could alternatively link to it in a comment on the question or in a comment on the most helpful answer.

    Although we disallow code in questions to be hosted on an external site, posting your revised code externally is fine, because:

    • The primary concern of the site is make justified suggestions for improving the code. The reviews are more valuable than the final product.
    • The "final" code is supplementary information that is not essential to the question-and-answer process.
    • Comments are considered disposable. If the link dies, we can just delete the obsolete comment.

In addition...

  • You must not edit the code in the question, as that would violate the question-and-answer nature of this site. (An exception to that would be if a user wrote a comment saying that your code is completely broken, and needs to be fixed before it can be reviewed.)

  • You also should not append your revised code to the question. Posting improved code is an answering activity, not a questioning activity. An example of such a problematic edit is Revision 2 of Optimize vector rotation. While the addendum to the question does not necessarily invalidate existing answers, it muddles the question. What are late-coming reviewers supposed to do? Reviewing the original code would be silly, but reviewing the revised code could lead to version skew among the answers.


On the other hand, that improvement would have made a good answer, since it was prefaced with a good justification for the code change. A reviewer who spots a problem with the revised code could post a comment, and it would be clear that the comment pertains to that revision. You could even post multiple selfie answers without muddling the original question.

Here are a few more illustrations of how adding revised code to the question is poor practice:


To end on a positive note, here is an example of what I consider to be a fruitful iterative review:

  1. Python Port Scanner
  2. Python Port Scanner 2.0
  3. Python Port Scanner 2.1
\$\endgroup\$
7
  • 1
    \$\begingroup\$ Regarding your third suggestion in the first block ("Add an answer") - would you consider it OK to change that code to reflect iterative improvement? \$\endgroup\$
    – Christoph
    Apr 14, 2014 at 8:41
  • 2
    \$\begingroup\$ @Christoph I think it's OK to edit an answer, within reason. Editing answers usually doesn't cause harm the same way that editing a question does. It's also OK to post multiple selfie answers, as long as they are all up to standard. \$\endgroup\$ Apr 14, 2014 at 8:48
  • 1
    \$\begingroup\$ That sounds promising. I wouldn't like opening new questions for each (major) revision, because they meight be hard to keep consistent. \$\endgroup\$
    – Christoph
    Apr 14, 2014 at 8:53
  • 5
    \$\begingroup\$ I should note that appending revised code to questions has been accepted practice on this site for some time. However, I've observed that it tends to make a mess of things, so I'm advocating selfie answers and follow-up questions as better alternatives. \$\endgroup\$ Apr 14, 2014 at 10:12
  • \$\begingroup\$ "Code-only answers are insufficient and are subject to deletion" is not what that topic says: it says that Code-only answers are acceptable unless the code that's posted is unrelated to the code in the OP to be reviewed. \$\endgroup\$
    – ChrisW
    Apr 20, 2014 at 21:11
  • \$\begingroup\$ @ChrisW I've reworded the admonition against code-only answers in Rev 9. For the record, I think that answers that contain code reviews within code comments are fine. \$\endgroup\$ Apr 21, 2014 at 9:15
  • 2
    \$\begingroup\$ Ideally, for review, you should wait a few days before accepting an answer. Give people a chance to find your question and review it. It's not like SO where you need an answer fast to solve your real life issue and get on with it. \$\endgroup\$
    – CashCow
    Aug 26, 2014 at 10:28
3
\$\begingroup\$

I came here because of

The moderators have had a discussion, and we are proposing new guidelines for posting follow-up code. Specifically, we would like to end the practice of letting the OP append revised code to a question. Since this is a departure from past practice, please read and provide feedback. We plan to upgrade this to faq status soon.

I personally like the appending of the new and approved code at the end once, it is the easiest way for people who want to post another answer to determine what has been addressed already or not. [@Jamal, agreed, multiple updates on a question -> do not want]

Also, it seems that this will generate more work for the mods, whom I thought were already busy ;)

Not the greatest arguments ever, but I still wanted to pitch in my 2 cents.

Edit:

What story is good without a single skewed point of data ;) This : node.js Passport Wrapper 2

This is the 3rd time that a person resubmits a JavaScript question that nobody responds to, costing me rep to put a bounty and keeping the answered score artificially low.

\$\endgroup\$
2
  • 4
    \$\begingroup\$ It would still be problematic to have new answers on updated code in the same question. If two or three updates is not enough, there may be a fourth. It can become very confusing very fast. By sticking to just the original code, there's a more direct link between the review and the code. \$\endgroup\$
    – Jamal
    Apr 14, 2014 at 20:29
  • 2
    \$\begingroup\$ Yes, but by sticking to the original code only, then the only real way to show progress is to post new questions for each iteration. This seems 'unwieldy' at best. Why not allow an area for the 'current working code' in addition to the original question. I do agree that the original question should remain untouched. But, as it is, there doesn't seem to be a good way to show progress within a question and that's a shame. Btw, the 'current working code' shouldn't count toward the poster's standing. \$\endgroup\$
    – Mark Ross
    Jul 5, 2014 at 6:55

You must log in to answer this question.

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