Example Project vs Example Code
It's example code that we don't want to see. Example code is hard to review because it either:
- lacks sufficient context (and/or)
- has identifiers with names like
foo
and bar
(and/or)
- has methods with placeholder comments
// ...
instead of actual code
@200_Success does a better job at describing this, here (in an answer to the linked meta-question).
In my eyes, 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?
It's ok for your question to point out what kind of feedback you're mostly interested into.
It's not ok for your code to do that.
A question asking how could I reduce nesting in this code?, with the below code, would be off-topic:
if (foo)
{
if (bar)
{
// do something
}
}
Another question asking how could I reduce nesting in this code?, with an actual method and enough context to be able to tell what's going on and why, with the below code, would be on-topic:
public IActor FindActor(string search)
{
if (search != "")
{
var actor = _repository.Actors.FirstOrDefault(actor => actor.Name.Contains(search));
if (!actor == null)
{
return actor;
}
}
return null;
}
Anyone else is biting their tongue to say "if (search != "")
should be if (!string.IsNullOrEmpty(search))
"? The two snippets could very well be 2 different revisions of the same question... by not narrowing it down and giving us real code to review, OP allows reviewers can pick up things that the OP didn't see... which is kind of the whole point!
Clarifications about where _repository
is coming from can be addressed in comments, without any exploding-bear-traps.