8
\$\begingroup\$

Often when I write an answer I write some code to go with it, ie "this method is written a little weird, you could simplify it as X, Y, Z, example". This code is not necessarily always perfect code - it might exclude some error handling, or some edge cases, or just not be written perfectly correct.

I then sometimes get a comment from the OP saying something like "this doesn't work for case T", or "this doesn't compile because of missing semi-colon", or whatever.

In my mind, when I review the code although I may rewrite all of their code to something that is more readable, efficient, or whatever, I never intend for it to be perfectly functional or compilable, or whatever. Rather I generally intend for it to be a general guide as to improving some aspect of the code.

Should I make sure that all of my code works perfectly and solves all of their needs? Should I make an explicit note that my code isn't tested and may or may not work? Should I just ignore people who blindly copy-paste my review and are surprised when it doesn't work as expected?

\$\endgroup\$
1
  • 4
    \$\begingroup\$ I do either, depending on how much effort I feel like putting in. The important thing is to communicate in your review whether the example code is "runnable-as-is" or "just a demonstration". \$\endgroup\$ Commented Aug 4, 2016 at 15:34

2 Answers 2

12
\$\begingroup\$

TL;DR; No, but you may get flak downvotes if you don't say it

From my experience Code Review doesn't have any "criteria" for answers, aside from

"It reviews the OP's code and justifies what it says"

Whether that review includes any code, fully functional code, pseudocode or an illustrative example thrown together is not that important. It's generally good tone to mark pseudocode and "demonstration" as such (though that's IMO easily recognizable). Also giving a quick heads up that you didn't test the code is not unheard of, but it's not mandatory, so long as it's not obviously broken.

Adding code is not mandatory in the first place, and OP is not entitled to a review being a free rewrite of their code. As such your code doesn't need to be "perfect".

\$\endgroup\$
3
  • \$\begingroup\$ Just to add to this answer, when I put code into a review I usually will provide the structure of the program such as the classes and methods. In general I don't fill in the actual code for the methods unless necessary. I usually add a comment line into the code to indicate that code was left out at that point. My point being, I make it clear that my code isn't meant to work but to provide an example to a concept I am trying to explain. I feel this is a better way to review code anyway. Programming is about ideas and concepts, not specific implementations. \$\endgroup\$ Commented Aug 12, 2016 at 15:20
  • \$\begingroup\$ It's not impossible to post an answer that you state "this code may or may not work" and still get plenty of up votes. \$\endgroup\$ Commented Aug 13, 2016 at 16:57
  • 1
    \$\begingroup\$ @EBrown additionally, you don't even have to know the language and still be helpful \$\endgroup\$ Commented Aug 16, 2016 at 11:33
8
\$\begingroup\$

Code Review is not a code-writing service. Answers are not required to contain code in the first place. The important part of the answer is the advice; the code serves as illustration. However, if you are going to provide code in an answer, you should believe that it is better than the original code in at least some respect. (If I see code in an answer that is worse than the original code overall, I'll usually downvote the answer.)

In any case, when readers evaluate answers, it's up to them to adapt the advice and whatever code it may contain as necessary.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.