12

I've noticed a lot of questions essentially asking this:

"Here's some code, am I doing this the best/right/most efficient way?"

(for example: How to prevent repeating code)

I'm curious if these are on-topic, and if not, what's the proper action?

5
  • Your question does not accurately describe the example that you've posted Commented May 29, 2014 at 15:59
  • 1
    it doesn't? OP says in the question text: Could this snippet of code be written more efficiently? Commented May 29, 2014 at 16:00
  • the example is specifically asking about how to avoid writing duplicate code. There's more to it than "here's my code is there a better way". Commented May 29, 2014 at 16:04
  • 1
    it's specific, but it still is looking for an opinion on how their code is written and soliciting ideas for either correctness or efficiency. Commented May 29, 2014 at 16:10
  • Let's be careful here. First we complain that users don't show any effort of solving the problem on their own. Then we say that if they do make an attempt at solving the problem, the question belongs on Code Review. Certainly it could be asked there, but it is perfectly on topic for Stack Overflow.
    – Cody Gray Mod
    Commented May 30, 2014 at 7:45

2 Answers 2

9

Of course every question needs to be evaluated on its own merits, and not all questions of the same form will have the same problems, but there are generally two things to look out for when you see a question that is like that.

The most likely is that it's just going to be too broad. This isn't necessarily the case, but usually there are just so many aspects of a code snippet that could each be evaluated independently that one can't expect a realistically scoped answer to completely cover all of them, nor do we want questions that collect a ton of answers each evaluating something different.

Another possibility is unclear, if it isn't clear what should be optimized, or by what metrics "best" is measured. Sometimes it's clear in context, sometimes it's explicitly stated, and sometimes the question is just unclear for not having it.

Note that there is an entire site devoted to questions of this form: Code Review. They do have standards (such as stating what metrics are to be evaluated) but there's a good chance that questions of this form that don't belong on SO can be altered in order to belong there.

5
  • so we should flag for moderators to move to code review? Commented May 29, 2014 at 16:03
  • 3
    @pennstatephil Usually not. Generally a question will need to be re-written to be in line with the rules and guidelines of that site. Unless you're familiar enough with that site to know that the given question meets all of those guidelines, you shouldn't flag it for migration. The question author should be reading through the site's guidelines and re-writing the post with that intended audience. The odds of the post needing no re-work are low, in my experiences.
    – Servy
    Commented May 29, 2014 at 16:05
  • Curious that this is getting downvotes, since it is essentially the correct answer.
    – Robert Harvey Mod
    Commented May 29, 2014 at 16:07
  • @Servy so, a good idea would be to ask the OP to rewrite the question on Code Review (using the appropriate guidelines, of course), and then remove it from SO? Commented May 29, 2014 at 16:11
  • 2
    @pennstatephil Yes. Assuming it doesn't actually meet SO's guidelines. Many of these questions don't, but some can.
    – Servy
    Commented May 29, 2014 at 16:12
-8

Close for primarily opinion based or off-topic

point them toward https://codereview.stackexchange.com/

3

You must log in to answer this question.

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