I recently answered a question that did not include a main method or any tests. The code provided was a just a handful of methods. Without any obvious way to drive the code, I had to guess at how each method would be used and how it should operate.

In my particular case, the question centered around porting code from one language to another, and the original implementation included documentation and tests for each method. However, these tests were not trivially runnable as I would have needed to rewrite them in the new language.

Should we expect people asking for review to provide a way to run the code, just as we expect a description of what the code does? Should the way to exercise the code be provided in the same language as the code under review?

  • 5
    \$\begingroup\$ I'm quite sure this meta question is a duplicate, anyone who finds the question it is a duplicate of gets a donut. Short answer then was, IIRC: No, code is not required to show how it should be run, but it is recommended to provide main method, test cases, or general instructions whenever possible. \$\endgroup\$ Commented Dec 1, 2015 at 14:51
  • \$\begingroup\$ @SimonForsberg donuts indeed! I looked, I swear! ^_^ \$\endgroup\$
    – Shepmaster
    Commented Dec 1, 2015 at 14:51
  • 1
    \$\begingroup\$ It's okay, duplicates are fine on meta. It will help further askers to find the answer. \$\endgroup\$ Commented Dec 1, 2015 at 14:53
  • \$\begingroup\$ @SimonForsberg I request my donuts. I like them with white chocolate glaze, please :) \$\endgroup\$
    – Vogel612
    Commented Dec 1, 2015 at 14:58
  • 1
    \$\begingroup\$ @Vogel612 that question body seems to be more about code being within the question itself though. I think there might be other meta questions as well. \$\endgroup\$ Commented Dec 1, 2015 at 15:03
  • 3
    \$\begingroup\$ @SimonForsberg I looked through all the 'is:question run' and 'is:question main' results, and didn't find any that asked if a main was needed. I did see 'what is too short', 'what is too long', 'is this code ok', type questions, I don't think we've had this question before. (Still could be wrong tho) The closest I could get is this: meta.codereview.stackexchange.com/questions/466/… \$\endgroup\$
    – Peilonrayz Mod
    Commented Dec 1, 2015 at 15:29
  • \$\begingroup\$ @SimonForsberg I think the fundamental "problem" asked about is the same... \$\endgroup\$
    – Vogel612
    Commented Dec 1, 2015 at 16:03

1 Answer 1


Should we expect people asking for review to provide a way to run the code?

We can't do that. Otherwise people posting parts of a larger project would have to turn their code into some kind of MCVE and that would defeat the whole purpose of a peer review ("Yeah you're right about X, but my actual real code does Y" is infuriating, and that's why we ask for your actual, real code and not a MCVE/boiled-down/"simplified version" of the code to be reviewed).

We ask that the code works to the best of OP's knowledge, partly so that we have grounds for considering "where's my bug?" questions as off-topic; that doesn't mean the code in the post has to be compilable and executable out of the question box.

In the case of that specific question, it would have been nice if the OP included the "translated" tests, but they decided that they only wanted the implementation to be peer reviewed - as far as reviewers are concerned, there are no tests.

Of course, not including the tests is making it harder for reviewers to post a rigorous/thorough review: it's up to you to decide whether such a question deserves your upvote or not. But no, not including a way to run or test OP's code does not make the question off-topic.

Should the way to exercise the code be provided in the same language as the code under review?

That's pretty specific to "translation review" questions, and my answer would be that ideally, yes - when a way to exercise the code is provided, it's better for it to be in the same language as the code under review (i.e. in the language the question is tagged with), and then the test code becomes code under review as well.

Remember that some of the best CR answers don't even include code; improving OP's logic and including the refactored code in your answer is very very nice and appreciated, but when the question makes it hard for you to do that without breaking anything or making wild assumptions, it's perfectly fine to just point out what the issues are, rather than going over and above, and actively improve OP's code.


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