37
\$\begingroup\$

I tend to disagree with point #2 on the Help Center:

Did I write that code?

I believe any code, written by one self or anyone else should be eligible for code review. Many a times, you're reviewing others' code.

Any specific reason for this restriction?

\$\endgroup\$

2 Answers 2

41
\$\begingroup\$

Note Accumulating multiple discussions about why the 'own code only' restriction is in place on Code Review

There are multiple reasons why Code Review has the restriction that the code has to be your own code.

Moral / Polite

The purpose of a code review is to provide constructive criticism. Criticism can only be constructive if given to the person who is the emotional 'owner' of the code. Many people consider their code to be their creative expression, and criticizing their code may feel like it is a direct criticism of them too. If a person volunteers for a code review here then it is expected that they are prepared for the criticism they may get. Without that voluntary submission, though, there would be nothing constructive about the criticism from the perspective of the person who wrote the code. Without the voluntary submission Code Review would be something like Code Crap where you go to laugh at and ridicule other people's code behind their back.

This can be abused even further. We have had instances on Code Review where 'managers' have requested their employee's code is reviewed, and the outcome of the review would impact that employee's job (fired?)

Practical

In real life, a code review happens as a routine part of the development cycle. It happens after the code is designed, developed, and tested and in the process of being committed to the code base in preparation for release. The person doing the review sits with the person who wrote the code, and they go through it together. If the reviewer has questions like "why are you doing it this way?" then the developer is right there to give the appropriate answer.

In Code Review, as an online resource, in a Q&A format, the expectation is that the text describing the code should explain why the code does things the way it does. Code that is just dumped without an explanation is, in Code Review terms, "unclear", and is likely to be closed as "Unclear what you are asking."

If the code is not your code, you cannot answer questions about what motivated certain implementation decisions, you can only speculate. By default, it is impossible for you to describe the motivations for the code if it is not your code, and thus the question is unclear. On code review this happens often enough for there to be a special off-topic close reason to cover this situation.

Taking this even further, questions on code review asking for an explanation of someone else's code are a complete reversal of the process. Questions like that are what we expect a code reviewer to ask, not what we expect to be asked by someone seeking a code review.

See: If your question contains someone else's code…

Legal

One of the reasons for the restriction is the implied licensing terms that are part of Stack Exchange. Anything you post here is automatically ascribed to the Creative-Commons ShareAlike type licensing. See Section 6 of your terms-of-service - subsection "Subscriber Content" here on Stack Exchange.

If it is not your code, then you have no authority to give away the licensing for it.

\$\endgroup\$
4
  • 6
    \$\begingroup\$ But what if the code's license is compatible? \$\endgroup\$ Feb 14, 2014 at 5:05
  • 2
    \$\begingroup\$ Good question, so, it goes two ways, in my opinion - 1) you are not a real legal expert, and you cannot decide whether it really is compatible. 2) you really can say for sure it is OK to post someone elses code... then, it will still be off topic, not for legal reasons though, but because the code review will be criticizing someone who is not aware they are being scrutinized (the legal reason is only one of the reasons it is/may be off-topic) \$\endgroup\$
    – rolfl
    Feb 14, 2014 at 5:11
  • \$\begingroup\$ Honestly, prefer "is this useful" over "is this legal", but I won't argue over the latter. For the former, I FE this is a perfectly valid question. Imagine asking, "Does this painting by Van Gogh truly represent X? " This is a valid question, and the artist is free to ignore all answers, but the asker is entitled to an answer. \$\endgroup\$ Feb 14, 2014 at 5:17
  • 1
    \$\begingroup\$ The "Legal" argument is simply a red herring/smokescreen, assuming the code is proveably already released under a compatible license. I don't see how submission can't simply require an URL to the code's license, and determine automatically in milliseconds whether it's compatible. In that scenario, the comment "If it is not your code, then you have no authority to give away the licensing for it." is irrelevant nonsense and should be deleted/modified. \$\endgroup\$
    – smci
    Mar 9, 2019 at 1:57
31
\$\begingroup\$

Proof by [extreme] example.

(based on a true story)

Not too long ago, someone posted one of their employees' code and asked for it to be reviewed by the community. The OP wrote that based on the feedback we would give him, that he would decide whether to keep or to fire that employee.

Would you write the same review if you knew that what you write can result in someone losing their job?

Would you even review it?

I wouldn't. I agree with the rule.


A more down-to-Earth answer is much simpler: reviewing someone else's code is simply against the spirit of Code Review - write your own working code, get it reviewed. Period.

I wish I could post my predecessor's code for reviewing here. But that wouldn't be nice.

\$\endgroup\$
1
  • 10
    \$\begingroup\$ If your desire is to fire the author or embarrass some unknown figure, you're probably violating the spirit of CR. But I think there are many cases where this is appropriate. I would prefer to defer the decision to the poster rather than decrying rules that apply in various settings. If you ask me to review some code, I'd like to do so without regard to your motives \$\endgroup\$ Feb 14, 2014 at 5:12

You must log in to answer this question.

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