10
\$\begingroup\$

I've seen a couple of answers have sections at the end of the post where it brings together all of the recommendations that have been mentioned in that post and re-writes the code using those recommendations.

Is this okay, or is it better to leave that part up to the OP of the question?

One example of this is an answer to "The Loaderless Bootloader".

\$\endgroup\$
5
  • \$\begingroup\$ possible duplicate of A code review without the code \$\endgroup\$
    – RubberDuck
    Jun 21, 2015 at 23:02
  • \$\begingroup\$ @RubberDuck I do not believe that this is a duplicate because this question is talking about re-writing the OP's code at the end of an answer, regardless of the answer containing any code before the end. \$\endgroup\$
    – SirPython
    Jun 21, 2015 at 23:08
  • \$\begingroup\$ Then I don't understand the question. It's well established that answers aren't required to include code. \$\endgroup\$
    – RubberDuck
    Jun 22, 2015 at 0:09
  • 2
    \$\begingroup\$ I understand that. The question is if it's okay to re-write the OP's code for the OP. \$\endgroup\$
    – SirPython
    Jun 22, 2015 at 0:20
  • 4
    \$\begingroup\$ Oh. Sure. Can't see why not. I think it depends on OPs skill level personally. If I think OP is capable of taking some advice and running with it, I won't bother with re-writing code. A lot of times how ever, I think OP needs to actually see how it can be done better. In that case, I'll usually at least put some psuedocode together. \$\endgroup\$
    – RubberDuck
    Jun 22, 2015 at 0:24

3 Answers 3

9
\$\begingroup\$

Often, when I put together an answer, I copy the OP's code in to my IDE, and then refactor things as I see the problems. Each time I make a change, I add it to my answer as a bullet-item of things that were "wrong".

As I work through the code, I build up my answer. It's then no real effort for me to copy the resulting code back to the answer.

What I am trying to say, is that for me, often, the "summary" code and the actual answer are simultaneously written. Further, I would not be able to write the answer nearly as easily if I could not code the changes and visualize the problems as I go.

So, having done the rewrite just to write the answer, it's no stretch to paste that too.

There is no rule against doing it, and I would rather people and the OP could see the result as I intended it to be without having to cobble things together themselves.

\$\endgroup\$
1
  • \$\begingroup\$ I do this too and often my reviews have lots of "middle refactorings" leading to the summary code. I find it gives a nice feel for how I got from a to d. \$\endgroup\$
    – RubberDuck
    Jun 22, 2015 at 23:23
8
\$\begingroup\$

Is this okay, or is it better to leave that part up to the OP of the question?

Yes, it is okay.

Yes, it can be better to leave it to the OP.

It depends really. It is up to you. I don't think there is a "right" way to do it.

I myself tend to do sometimes include some re-written code, sometimes not.

\$\endgroup\$
8
\$\begingroup\$

If the question is tagged , then avoid giving away the solution. Otherwise, how you write your review is up to you.

\$\endgroup\$

You must log in to answer this question.

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