This got closed as off-topic. I read the help center and from it I concluded that rather than present possible alternatives in my question, it is better to just post my code and ask if anyone has ideas.

So I edited it. Is this question now considered on topic? I feel like I've vandalised my post in a desperate attempt to make it on topic.

Was the question better before or after the edit, and are either of them considered on topic? How could I get it on topic?

  • 2
    \$\begingroup\$ I have temporarily locked your question while discussion takes place here. If the issue is resolved before the 1-hour period, please flag for unlocking. \$\endgroup\$
    – Jamal
    Commented Dec 18, 2013 at 15:52
  • \$\begingroup\$ @Jamal, what is this 1-hour period you speak of? \$\endgroup\$
    – Malachi Mod
    Commented Dec 18, 2013 at 16:11
  • 1
    \$\begingroup\$ @Malachi: It is the period of time in which the main site question will remain locked. If it has not been manually unlocked before that time, then it will unlock automatically. \$\endgroup\$
    – Jamal
    Commented Dec 18, 2013 at 16:14

3 Answers 3


It's good that this question comes to attention because I have been wondering myself if "best-practice - Should I do A or B?" belongs here or not.

Personally, I feel that they don't, unless you have a good example with real code and some context. See here for an excellent question about this that is on-topic: Perform instruction in loop every time except the last time?

As for your specific question, it lacks both context and real code:

  • What are you really trying to do? How are you really using this in your code and why? (Providing this helps a lot to avoid XY problems)
  • //some statement(s) is not real code. The code you have provided is purely theoretical, and theoretical code should go into a theoretical compiler before being posted here.
  • \$\begingroup\$ To be clear, is it your opinion that if I posted the actual bit of code, rather than fake variable names and a commented out block then it would be on-topic? \$\endgroup\$
    – Cruncher
    Commented Dec 18, 2013 at 17:04
  • \$\begingroup\$ @Cruncher Yes, that's my opinion. I think you should keep it (more or less) in the form: "This is my code, this if-statement feels ugly to me, can I do this better?", and not in the form "This is my code, but I was thinking about doing this instead, which one is better?". However, this is just my opinion. \$\endgroup\$ Commented Dec 18, 2013 at 17:16
  • 2
    \$\begingroup\$ As Jeff Atwood quoted: "Does this code make my ass look fat?" is what CR is all about :) \$\endgroup\$ Commented Dec 18, 2013 at 17:33
  • \$\begingroup\$ I've been thinking about specifically asking a question about "which is better" or "A vs B" questions for a while. I feel like most of them are off topic, but they also tend to lure in a lot of site traffic, answers, and lots of upvotes. If upvotes + answers = on topic then I may be wrong. But maybe most people who use the site don't know what it's for? \$\endgroup\$
    – Daniel
    Commented Dec 18, 2013 at 18:39
  • \$\begingroup\$ @DanielCook I believe that most people who are here knows what the site is for (thankfully), but of course, every now and then someone comes along which has one idea about what the site is about and then learns about the truth the hard way. \$\endgroup\$ Commented Dec 18, 2013 at 18:45
  • \$\begingroup\$ @SimonAndréForsberg Well, to be fair, it took a moderator to raise attention that it was off-topic. The community seemed to be favourable of it until then. \$\endgroup\$
    – Cruncher
    Commented Dec 18, 2013 at 21:54
  • \$\begingroup\$ @Cruncher Probably because it isn't clear enough what our policy is regarding this. I was skeptical to the question at first, but I wanted to wait and see. Unfortunately, I think many questions similar to your original question will end up in "conventions holy wars". It's just too much opinion based sometimes. \$\endgroup\$ Commented Dec 18, 2013 at 22:24
  • \$\begingroup\$ @SimonAndréForsberg This site is opinion-based though. To quote Jeff Atwood: "In other words, general broad-spectrum subjective feedback about blocks of code you've written." \$\endgroup\$
    – Cruncher
    Commented Dec 19, 2013 at 13:47
  • \$\begingroup\$ @Cruncher Absolutely. One of the foundations about performing a Code Review is that it is supposed to be opinion based. However, there are some holy wars in programming which is simply too much based on opinion, where there is no consensus about "what is right, what is wrong". \$\endgroup\$ Commented Dec 19, 2013 at 13:51
  • \$\begingroup\$ @SimonAndréForsberg Okay. But now you see the problem. When you say "this is too opinion-based" and "this is just opinion-based enough" you create a slippery slope. The line seems difficult to accurately define. Sure you can show extreme cases like you did where it's obvious. But there are cases on the line. Which is what brought up this discussion to begin with. To digress: I think this question should have gone through the community queues rather than a moderator taking action to close it. \$\endgroup\$
    – Cruncher
    Commented Dec 19, 2013 at 13:56
  • 2
    \$\begingroup\$ @Cruncher To me it's too opinion based when you pose a question like: Should I do A or B? This automatically biases the reader into thinking A vs B, and not even considering C. If you simply showed us what you did (choosing A for example), you may get suggestions to do B or C or D etc. Upvotes would help you to determine which suggestion is more universally liked (obviously you still choose your favorite). By suggesting opinions you expect you're limiting the usefulness of a code review question before it's even submitted and increasing the chance of a "holy war". \$\endgroup\$
    – Daniel
    Commented Dec 19, 2013 at 18:51
  • 2
    \$\begingroup\$ I've added guidelines to the tag wiki. \$\endgroup\$ Commented Dec 20, 2013 at 1:40

The spirit of Code Review is to get actual code from actual projects you're working on, peer reviewed by a community.

If the entire code in your question is this little snippet:

if(a) {
    if(b) {
        //some statement(s)
} else if(c) {
    //some statement(s) (the same ones as in the other block)

Then the question isn't about reviewing your code, it's about ways to write the code for a hypothetical conditional statement, where a hypothetical code block would be duplicated in two branches.

IMHO, the "answer" is something like: if(a && b || !a && c) { /* some statement(s) */ }.

This isn't a code review question, I think it would be more on-topic on Programmers.StackExchange.

On the other hand, if you supplied your actual code, with the actual repeated code blocks, and asked "how bad is duplicating a code block?", answerers could actually review your code, and address the duplication concern.

Just providing a "sample code" snippet to illustrate a hypothetical situation, is off-topic IMHO, because it goes against the spirit, it's too high-level and more on Programmers.StackExchange's grounds.

  • \$\begingroup\$ It feels redundant is all. I could have pasted the actual code, but this seemed easier to read. Are you saying it would be better to provide this snippet as I have it now, or even provide code further out? \$\endgroup\$
    – Cruncher
    Commented Dec 18, 2013 at 17:02
  • 4
    \$\begingroup\$ The point is whether you're looking for a code review (where actual code matters) or for an answer about the specific situation (where actual code can be placeholder comments). Only one of the two is on-topic. \$\endgroup\$ Commented Dec 18, 2013 at 17:04
  • 2
    \$\begingroup\$ Based on what I've seen so far here, for me to make this on-topic(and I have a specific edit in mind) would make this a chameleon question and potentially invalidate some answers. Am I best off to just let it be closed? I did get the answer I was looking for. \$\endgroup\$
    – Cruncher
    Commented Dec 18, 2013 at 17:07
  • 1
    \$\begingroup\$ @Cruncher: Yes, it can just stay closed. It'll remain since the answers are valuable and can still help others. If you're ever inclined to ask best-practice questions in the future, I encourage you to refer to these answers for guidance. \$\endgroup\$
    – Jamal
    Commented Dec 18, 2013 at 17:23

the question needs certain things for it to be on-topic

  1. your code (not someone else's code)
  2. needs to be real code
  3. the code needs to do what it is intended to do (it needs to work)
  4. no known bugs
  5. does not ask for code to be written
    • you aren't trying to get us to write a method or class for you.
    • you aren't trying to get us to fix something that isn't working the way you intended.

You must log in to answer this question.

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