When expanding the guide to wonderland, I'm trying to explain what example code, stub code and context are. When trying to explain why example code is off-topic all I can think of is something like:
The only purpose that is off-topic on Code Review is example code. If your question includes these then it's likely to be closed.
Note: This isn't always off-topic, and is normally only off-topic if it contain insufficient context to review them.
This doesn't sit right with me. It's basically just an odd way to say example code normally has insufficient context.
This doesn't seem like example code is the actual reason example code is off-topic, and so make me think this is an XY problem. This is as I've posted example code before, and had only the example code reviewed. So if example code is the primary reason this is off-topic then that question and answer should be off-topic.
To be able to compare the differences between the two, I've gone through both context and example code links, and have quoted the reasons these are on/off-topic from the answers.
Context
is there a threshold of 'enough' reviewable content?
- Do one-liners and other narrowed-down code qualify for a code review? - rolfl
Posting excerpts from your project is fine, as long as we have enough context to give you the best advice possible.
- Can I ask for review for something specific without posting too much context? - 200_success
lacks sufficient context
- The gray areas of Code Review: Hypothetical / Example code - Mathieu Guindon
Why is this question problematic? It has been stripped of all context, making it hard to give concrete advice.
- Why is hypothetical example code off-topic for Code Review? - 200_success
If your question contains stub code, then there are significant pieces of the core functionality missing, and we need you to fill in the details.
- My question was closed as being off-topic. What are my options? - 200_success
Example Code & Context
If this question was posted on CR, I think it's too narrow and should be closed as off-topic. Not only because the names are "generalized" and the thing looks like pseudo-code, but also because there's such little context, that leaving the actual names of the involved identifiers in there, is irrelevant. This goes against the spirit of "3. Is it actual code from a project rather than pseudo-code or example code?".
- Do one-liners and other narrowed-down code qualify for a code review? - Mathieu Guindon
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.
- Can I ask for review for something specific without posting too much context? - 200_success
If your code was deemed to be example code, too hypothetical to be meaningfully reviewed, then we need you to provide concrete details.
- My question was closed as being off-topic. What are my options? - 200_success
Is it actual code from a project rather than pseudo-code or hypothetical code?
Details matter! In order to give good advice, we need to see real, concrete code, and understand the context in which the code is used. Generic code (such as code containing placeholders like foo, MyClass, or doSomething()) leaves too much to the imagination.
- Help center
Example Code
In practical terms, though, any plausible realistic code is acceptable too.
- Can I ask for review for something specific without posting too much context? - 200_success
We could review example code, but have decided not to
- Are requests for review of language design on topic? - amon
The line between real and hypothetical code is sometimes blurry, but I would consider this code sample to be on the wrong side of the line for Code Review.
- Is asking for a review of boiler plate for a minimal repro okay? - 200_success
Now, in general, the second we see a name like FooBar, we hit the close button because it's example code and example code causes frustration for the reviewer & reviewee alike.
- Is asking for a review of boiler plate for a minimal repro okay? - RubberDuck
Any or All
When all the OP wants to know is how a tiny little piece of code could be written better, the purpose of the site is thwarted and Do I want feedback about any or all facets of the code? doesn't hold anymore, because there's only 1 facet to review.
- Do one-liners and other narrowed-down code qualify for a code review? - Mathieu Guindon
this aims at narrowing down the scope of the review, in getting a quickie that goes against rule #6 (which isn't being questioned here):
Do I want feedback about any or all facets of the code?
- The gray areas of Code Review: Hypothetical / Example code - Mathieu Guindon
Other
There's the implicit expectation that no matter how simple it may seem to some, it constitutes an area of enough uncertainty to warrant a review for the one asking.
- Does a single shell command constitute reviewable code? - Legato
The above shows that we use the same reasoning for both insufficient context and example code.
It also shows that stub code is code that has insufficient context but isn't example code.
I think it would make more sense to say that insufficient context is off-topic, rather than example code or stub code.
This would make our scope simpler:
- It merges two confusing groups into one simpler one. Whilst removing the example code edge cases.
- It helps removes example code bias, meaning it's easier to not pattern match example code and close otherwise on-topic questions.
- We can say all known purposes for code are on-topic.
How would this affect our site?
- It would mean that we may need to reword the 'Lacks concrete context' close reason.
- It would not change which close reason to close these questions as.
- It would not mean that we need to change our help center.
I think we should still point out that example code commonly has insufficient context and so is commonly off-topic. But example code isn't off-topic.