7
\$\begingroup\$

Is it on-topic to ask a question with two more or less equivalent snippets, and ask which of the two snippets is considered the most clean?

The way I see it, there are four possible answers here:

  1. Snippet #1, because [reason].
  2. Snippet #2, because [reason].
  3. It's a matter of taste (because [reason]).
  4. You should write it like this [demonstration] because [reason].

The obvious concern here is questions that are likely to cause debate. Would the potential-debate-factor be limited by the limited set of answers? Are such questions more prone to debate than regular code review answers?

Example

switch (score)
{
    case 0:  return "Love-All";
    case 1:  return "Fifteen-All";
    case 2:  return "Thirty-All";
    case 3:  return "Forty-All";
    default: return "Deuce";
}

vs.

if (score > 3) return "Deuce";
string[] scoreNames = { "Love-All", "Fifteen-All", "Thirty-All", "Forty-All" };
return scoreNames[score];
\$\endgroup\$

2 Answers 2

6
\$\begingroup\$

To me, such questions are interesting and useful. There's not much difference between saying, "here's my code, is there a better way of doing it" and "here's two pieces of my code, which is the better way of doing it".

The poster could of course post both pieces of code in two separate questions, each of which is 'valid' in the narrow sense. But I don't see that this helps either the poster or the site.

\$\endgroup\$
1
\$\begingroup\$

As long as the code is real (non-example), belongs to the asker, and still involves review, then yes, it is okay to post such questions. In fact, we already have a tag for this.

\$\endgroup\$
2
  • \$\begingroup\$ Hey @Jamal :) What exactly do you mean by 'still involves review'? \$\endgroup\$
    – Lstor
    Jul 18, 2014 at 7:02
  • \$\begingroup\$ @Lstor: I mean that the OP must still be willing to have the snippets improved, rather than just hearing which is better and why. Otherwise, it could possibly be closed as primarily opinion-based. \$\endgroup\$
    – Jamal
    Jul 18, 2014 at 12:46

You must log in to answer this question.

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