20

It's not uncommon for me to see someone post a question regarding one thing wrong with their code, but in reality, there are multiple issues that they evidently haven't noticed yet. I've noticed if you only deal with the primary concern, you'll inevitably get "but what about x, y, and z problems?" comments on your answer, urging you to address everything.

Case and point: I just answered a Python question where the main problem was inconsistent indentation causing an error. In their code though, they also attempted to compare numbers using =. Someone else and I posted an answer, and not long after, someone posted a "what about the assignment operator being used to compare?" comment.

What's the general feeling on this?

While I don't see a small little blurb pointing out a side issue as a problem, I have seen cases where the "side issues" take up more of the answer than the title problem. To me, other problems shouldn't detract from the problem in the title; especially considering the purpose of the site.

Should other issues be pointed out? Should people be commenting asking for side things to be pointed out?

8
  • 19
    SO is not Code Review, you're free to provide a full analyze of the OP's code but you don't have necessary to do so. If the others wants to do so, they're free to leave comment on OP's post or make a full fledge answer on their own.
    – Walfrat
    Oct 17, 2017 at 12:06
  • 1
    It can be a best practice to point out blatant security related flaws; say SQL injection issues. Questions and answers don't necessarily have to be as secure as they can be depending on their context, but apparently people blindly copy & paste a lot and that is Stack Overflow's fault.
    – Gimby
    Oct 17, 2017 at 14:06
  • 4
    I'd rate an answer better if it included a solution as well as helpful tips or fixes the OP may not be aware of.
    – user1228
    Oct 17, 2017 at 17:25
  • 2
    seen cases where the "side issues" take up more of the answer than the title problem Yes this actually sucks sometimes Oct 17, 2017 at 18:24
  • Fixing the problem is usually the first step. I prefer writing an answer that says, "yeah, you could do this... BUT, here's a better way!". Example...
    – cs95
    Oct 17, 2017 at 19:33
  • For the particular question you are referring to, I made that comment to the other answerer as it was a fairly obvious misuse of = as it was that bit of code included in the error message. I think if it is a small enough side issue (you handled it in one sentence) then there is no harm in pointing it out
    – DavidG
    Oct 17, 2017 at 19:44
  • @DavidG Sorry, didn't mean to sound like I was harping on you or anything. It's just a question I've been wondering for awhile, and this situation was a good example of it. I've made similar comments (and answers) for glaring things. Just wanted to know the community's opinion on the practice. Oct 17, 2017 at 22:53
  • @Carcigenicate No worries, I didn't take it that way :) I suppose the problem is that people who are new to coding might get an error message which stops them running code, like an indentation error, and not actually reach other problems they might have, where more experienced people can see it straight away. Interesting to know whether it would be best to leave them to figure out the "other" problems themselves?
    – DavidG
    Oct 17, 2017 at 23:12

5 Answers 5

30

There's nothing wrong with pointing out side issues, either in your answer or in a comment. In an answer, I like to make sure I address the main issue first, then review any other issues that I see. Nobody can force you to do a complete breakdown of all the issues in a question, but be aware that other more complete answers often get more upvotes than one that stops after explaining the first problem.

2
  • 13
    Which is why we ask for MCVE.
    – Braiam
    Oct 17, 2017 at 18:17
  • Excellent answer. Some are beginners, some are advanced. For beginners, firstly, answer the question itself. Secondly, show him how to do better. Oct 17, 2017 at 19:38
9

If it's going to result in the same person coming back to the site with the same block of code but a different question, I generally try to point out what's wrong in a single answer. If there are multiple issues that would cause the code presented to not meet the OP's expectations, it's nice to point them out.

Then you run into those times where you realize that you're about to write a novel. At that point, I recommend that you stop, and just point out that the code has issues that are too numerous to describe in-depth and perhaps recommend some tutorials (in addition to answering the primary question).

In short, always answer the question at hand; it's nice to go above and beyond, but don't write a book on programming every time you do so. If the issues are really basic there's a very good chance that they're covered multiple times on the site, so your time might be better spent turning up a few links to include as supplemental to your answer (since you know what to search for, which probably eluded the OP).

5

Ask yourself this: does pointing out all the flaws in this person's code produce a helpful document for another person later? (And will they find it if it's attached to this particular question?)

The answer to this is the same as the answer to your question.

4

I may be in the minority on this, but I think it's better to confine my answer to the one aspect the person is actually asking about, and not address other problems with the code. That way, people who come along later with the same problem in a different context will find an answer that is relevant to their case as well, without having to read through a bunch of feedback that is specific to the code sample presented in the question.

If I do see a bunch of other issues with the code, I may leave a comment on the question like

Once you get your problem resolved here, you might want to take this to [codereview.SE] for more general feedback.

And if people (including the asker) comment on the answer asking about those other problems I haven't addressed, I'll respond with something like

That would be a good topic for a separate question.

1

In most cases I only address the main issue. But I (try to) avoid copying part of OPs code into my answer if it has a bug. Thereby I avoid other SO members from pointing at my answer and say it's wrong.

So my answer to your question is:

No, it is not required to point out every problem in the code provided by OP. Just focus on the main point and avoid copying bugs into your answer.

You must log in to answer this question.

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