I'm working on an Angular2 application and I think one very small, specific function (list filtering) needs improvement and I would welcome reviews. Essentially I iterate more times than I think is necessary (meaning it could be done more efficiently -- which is the reason I am seeking review).

My scenario amounts to: I do this thing in 4 passes, is it possible to do it in a single pass through a method I am not familiar with?

Given the way CR.se appears to work, I'm wary of posting merely the function body some sample data because the function makes references to class members. I foresee "but where's the rest of your class?", which is frankly irrelevant to the question.

I could trivially re-implement a semantically-identical function which is not my original code. I can trivially create an MCVE that is runnable within an in-page snippet which conveys my problem.

But that raises the question, does that make it a "Let's suppose" question? I think it might.

If so, should avoid CR.se and just post it to SO?

EDIT: To close the loop, this is the question I eventually asked: Create several homogeneous arrays from a larger heterogenous array efficiently

  • \$\begingroup\$ Certainly not on SO, where a MCVE is required. \$\endgroup\$ Commented Mar 15, 2017 at 17:55
  • \$\begingroup\$ @πάνταῥεῖ That's the point, though: I can make an MCVE trivially that is runnable within a snippit. The problem I have on CR.se is that this seems to break the "original complete code, please" requirement. My problem, so to speak, is specifically with the array filtering algorithm. \$\endgroup\$
    – msanford
    Commented Mar 15, 2017 at 17:57
  • \$\begingroup\$ "Essentially I iterate more times than I think is necessary." That sounds your code doesn't work as intended, which would make such question off-topic here. \$\endgroup\$ Commented Mar 15, 2017 at 18:00
  • 2
    \$\begingroup\$ @πάνταῥεῖ I will rephrase: it iterates more times than is perhaps optimal. Indeed, it works as intended because the output is correct. My scenario amounts to: I do this thing in 4 passes, is it possible to do it in a single pass? \$\endgroup\$
    – msanford
    Commented Mar 15, 2017 at 18:01
  • 5
    \$\begingroup\$ @πάνταῥεῖ Doing something more times than necessary is an optimization problem, not a problem with code not working as intended. \$\endgroup\$ Commented Mar 15, 2017 at 21:03

1 Answer 1


Strictly speaking, Code Review requires you to post real code from a project that you are working on.

In practical terms, though, any plausible realistic code is acceptable too. If your real project is a shopping cart for a porn site, and you decide to post the question as a shopping cart for a clothing site, that's fine. Just make sure that the code still works correctly, and don't mention the substitutions or include any "Let's suppose" disclaimers. It would be up to you to figure out how to apply the advice about the clothing site to your porn site. You'll have to accept the risk that answers may talk about clothing-specific issues that you are not interested in.

Posting excerpts from your project is fine, as long as we have enough context to give you the best advice possible. Exactly how much context is necessary is tricky to determine. Try to put yourself in the reviewer's shoes — can you make sense of the code, based only on what was included in the question?

Some questions could be appropriate for either Code Review or Stack Overflow, depending on how you choose to frame the question. Simplifying the code for the sake of posting a question is not a practice that I recommend for Code Review. If the example looks too hypothetical to be realistically part of a real project, then you will likely receive negative feedback. If you prefer to frame your question using an MCVE rather than a realistic excerpt with contextual information, then the question would probably be more appropriate for Stack Overflow. (See A guide to Code Review for Stack Overflow users to understand the distinction between the sites.)

  • \$\begingroup\$ Brilliant analogy, and something I have considered (though in a different context). This will become a canonical reference for me going forward, including the comments above from @πάνταῥεῖ. Thank you both. \$\endgroup\$
    – msanford
    Commented Mar 15, 2017 at 18:46

You must log in to answer this question.

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