4
\$\begingroup\$

We have a consensus view that questions asking for re-writes of code are off-topic, but we still get a lot of these. Some examples:

Others can be easily found, e.g. with a search.

Could we have add a line to help/dont-ask specifically mentioning that such rewrite requests shouldn't be posted? This would be helpful to quote in a comment when voting to close these questions.

\$\endgroup\$
  • \$\begingroup\$ Can you give an example of such a request (perhaps anonymized, to avoid the meta effect)? Does "How can I make this code faster” count as a re-write request? \$\endgroup\$ – Martin R Aug 14 at 7:39
  • 1
    \$\begingroup\$ @MartinR I think he means more along the lines of "I want to make this OO code using functional instead". \$\endgroup\$ – Mast Aug 14 at 7:44
  • 3
    \$\begingroup\$ Some reference to this “consensus view” would still be helpful. Has this been discussed on meta? \$\endgroup\$ – Martin R Aug 14 at 7:54
  • \$\begingroup\$ @Martin - edited to add a recent example. I didn't think it needed a discussion on Meta to form a view; I'm just going by the close votes on such questions. \$\endgroup\$ – Toby Speight Aug 14 at 8:00
  • \$\begingroup\$ @Mast, that's exactly the kind of thing I'm thinking of. \$\endgroup\$ – Toby Speight Aug 14 at 8:08
  • 2
    \$\begingroup\$ Isn't “Code not implemented or not working as intended” good enough as a closing reason? – I am a bit concerned that “do not ask for a code refactor/re-write” is too generally applicable. Many questions are implicitly requests for some re-write, such as the (on-topic) [time-limit-exceeded] questions. \$\endgroup\$ – Martin R Aug 14 at 8:09
  • 3
    \$\begingroup\$ @MartinR The problem is the code in those questions usually works. Not in the style they want, but the result is satisfactory. There's a difference between "my code is a mess and I should probably use Z to fix it" and "I'm doing X using Y. Help me do it in Z instead.". The first is fine, the second is almost offensive. That's one particular kind of rewrite-request we encounter. Another is the "this works for 1 set, I want to have it work for 100 sets". In which case it's a simple case of the code doesn't yet work as intended. After all, the intention is 100 sets. Not 1. So, not ready. \$\endgroup\$ – Mast Aug 14 at 8:16
  • \$\begingroup\$ I thought this question was about the first kind of question, but the example shows the second kind of question. We could make it more explicit in the help that code already has to produce the result for the amount of input you're going to provide. However, that has its own pitfalls. \$\endgroup\$ – Mast Aug 14 at 8:20
  • \$\begingroup\$ @Martin, “Code not implemented or not working as intended” is certainly the correct close reason, and I see no need to change that. But some askers (citation needed) respond with "but it produces the correct output" and it would be nice to have a definitive statement to point those ones to. \$\endgroup\$ – Toby Speight Aug 14 at 8:56
  • \$\begingroup\$ @Mast, I might not have produced the best example. I'll see if I can dredge up another. \$\endgroup\$ – Toby Speight Aug 14 at 8:57
  • 1
    \$\begingroup\$ With respect to the 3rd example: The question “This code is working but there's a lot of duplication, how can I refactor it?” would be discouraged, but a question “Here is my working code, how can I improve it?” (with an answer “Refactor it like this, to avoid the code duplication”) would be on-topic? – (Don't get me wrong: I am not against your suggestion. I just think that it might be difficult to find the correct wording, so that it applies not to too many questions.) \$\endgroup\$ – Martin R Aug 14 at 9:42
  • 2
    \$\begingroup\$ @Martin - yes: an answerer may choose to suggest a refactor, but AIUI we don't do re-writing requests. And it is a good idea to edit if it's possible to bring such a question back on topic (that question had other problems which make it unsalvageable). \$\endgroup\$ – Toby Speight Aug 14 at 9:45
  • 5
    \$\begingroup\$ Related: codereview.meta.stackexchange.com/questions/8789/… - I don't think there is "consensus" as much as you suggested. \$\endgroup\$ – rolfl Aug 14 at 12:12
  • 1
    \$\begingroup\$ @TobySpeight What you might be after could be that we don't like requests of the form "Please write the code for me". Answers are allowed to rewrite code completely and come up with a new updated version with all the suggested fixes implemented, but answerers shouldn't be forced to do this. I don't think this is about being on-topic or off-topic though, it's more about something being frowned upon and should possible be down-voted. An answer that explains what needs to be done and how to do it should always be acceptable, even if it doesn't provide the exact code for it. \$\endgroup\$ – Simon Forsberg Aug 20 at 10:38
  • 1
    \$\begingroup\$ What's the point of this website if people can't get help with improving their code? If it's only a website for improving very specific algorithms, it should be called "algorithms.stackexchange.com" \$\endgroup\$ – devinbost Aug 20 at 14:21
5
\$\begingroup\$

We have a consensus view that questions asking for re-writes of code are off-topic

Citation needed. I don't agree about this at all.

Refactor Linq Expression

Simple code refactoring in javascript

These questions are not off-topic. This is closed as unclear what you are asking because there is absolutely no description whatsoever about what the code does. There are a lot of "How can I refactor this code"-requests that are completely on-topic. In fact, I'd say most of them are.

Making this Pygame code object-oriented

This question is not off-topic because it asks to make the code OOP, it's off-topic because the OP is saying "I get this syntax error now, tried multiple things without progress." and quotes the syntax error in the question.

So of all three examples of questions that are "questions asking for re-writes of code", NONE OF THEM are off-topic for that reason.


I think the questions you are asking about are what I'd like to call "specific refactoring requests", which is basically when a question asker has self-reviewed their code beforehand, identified something that needs to be changed, then comes here to get more detailed help in accomplishing this. As rolfl pointed out in a comment, this discussion has existed before on meta and I've shared my opinion about it before. I don't think we should be so nit-picky here so that we essentially tell OP's "Your current question is off-topic because you are formulating it (this way), if you instead would formulate it (that way) then it would be on-topic".

There's nothing wrong with asking for re-writes of code, all our on-topic questions here are about rewriting code in one way or another.

\$\endgroup\$
  • 1
    \$\begingroup\$ I find they are all off-topic exaclty for that reason and for others like no description or lack of context. If the code wasn't OO before then asking for rewriting it as OO is a feature request. \$\endgroup\$ – t3chb0t Aug 20 at 10:42
  • \$\begingroup\$ @t3chb0t It's asking for the code to do the same thing in a different way. Object-orientation is not a feature but a paradigm. \$\endgroup\$ – Simon Forsberg Aug 20 at 10:43
  • 3
    \$\begingroup\$ @t3chb0t I really don't understand that line of thinking. Clearly the fact we allow TLE, performance, memory, etc, reviews shows we allow some feature requests. And depending on your definition of 'feature', all Code Review questions are feature requests - where the OP is asking for cleaner more maintainable features for their code. \$\endgroup\$ – Peilonrayz Aug 20 at 11:06
  • \$\begingroup\$ Not all on-topic questions demand re-written or re-structured code. After all, the default implied question is more like "is this code as good as it can be, or are there areas I should improve?" (I guess you mean that's still about re-writing code, but two different expectations of who does the actual rewriting?) \$\endgroup\$ – Toby Speight Aug 20 at 14:34
  • 3
    \$\begingroup\$ I agree in general, although I feel like there is point where such a question can become a "gimmeh teh codez" question. I think as long as reviewers are free to not refactor it like the OP wanted but give the advice the OP needed, all is good. \$\endgroup\$ – Graipher Aug 20 at 15:49
  • \$\begingroup\$ @Graipher I agree, and I added another answer to address that as I think that is mostly a separate point. \$\endgroup\$ – Simon Forsberg Aug 20 at 16:13
  • 1
    \$\begingroup\$ @Peilonrayz They're bugs, not features. You've obviously spent too much time working in the software industry. :) \$\endgroup\$ – TorbenPutkonen Aug 21 at 4:27
  • \$\begingroup\$ Specific refactoring requests are a slippery slope. Do you have suggestions on how to handle this? After all, any aspect of the code posted is fair game for feedback and criticism and we've had problems in the past with users calling out an answer for being off-topic. They were wrong, but I can understand the confusion if we'd actively support specific refactoring requests. There's a risk of arbitrariness too. \$\endgroup\$ – Mast Aug 21 at 6:38
  • \$\begingroup\$ @Mast Sure, there's always a risk with this. I can't make up a general rule that can attempt at cover each case. My experience though is that if you do it the right way, and explain why, reviewing code in a way the OP doesn't want it to be reviewed can still be helpful. I believe this meta answer of mine is relevant. But always try to help the OP. If they ask about a specific refactoring, then don't post an answer that is only nitpicking about naming. If they ask about specific refactoring and their naming is horrible, then say that. \$\endgroup\$ – Simon Forsberg Aug 21 at 9:11
  • \$\begingroup\$ @Graipher We've been saying that since way back in 2015. \$\endgroup\$ – Peilonrayz Aug 22 at 16:48
  • \$\begingroup\$ @Peilonrayz I know. Just wanted to make sure that was not lost. \$\endgroup\$ – Graipher Aug 22 at 16:50
  • \$\begingroup\$ @SimonForsberg If they ask about a specific refactoring, then don't post an answer that is only nitpicking about naming I disagree. Any insightful observation should be welcomed, regardless what OP specifically asks for. nitpicking about naming is formulated in a way I would like to agree with you, but making a semantics- or conventions-only review should be OK. I got my top comment this way: codereview.stackexchange.com/questions/225391/… =D \$\endgroup\$ – dfhwze Sep 4 at 17:56
  • \$\begingroup\$ @dfhwze That's a good answer containing general PEP 8 suggestions, that's perfectly fine. But the best part there is that there is another answer addressing the more specific concerns by the OP. If your answer was the only answer, then it would be sad. \$\endgroup\$ – Simon Forsberg Sep 4 at 20:31
3
\$\begingroup\$

(Adding another answer as this addresses a different point, and what might be the actual concern here)


What you might be after could be that we don't like requests of the form "Please write the code for me". Answers are allowed to rewrite code completely and come up with a new updated version with all the suggested fixes implemented, but answerers shouldn't be forced to do this.

I don't think this is about being on-topic or off-topic though, it's more about "write the code for me"-questions and attitudes being frowned upon and should possibly be down-voted. (NOT CLOSED!) An answer that explains what needs to be done and how to do it should always be acceptable, even if it doesn't provide the exact code for it.

However, if you are willing to down-vote "How can I remove the duplication of this code using functional programming?" and not "How can I remove the duplication of this code?" I would recommend that you consider what the OP wants or needs. Neither of those questions literally says "Write the code for me".

\$\endgroup\$

You must log in to answer this question.

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