6

For example, if someone posted a question and attached a few lines of code with it, and the OP is asking about a specific portion of the attached code.

Let's assume the main issue has been addressed, however there are still some parts in the program which will, if run, cause conflicts or errors.

Is it okay to point out these even if the OP hasn't explicitly asked about them?

2
  • 5
    Why not? At best, the OP is thankful for turning his attention to these errors, or OP ignores the comment. Worst case would be that OP explicitely tells you that this is not relevant/off topic. I often even start such comments with "off topic". As long as you're not obtrusive, I don't think anyone would mind a comment.
    – Thomas
    Oct 8, 2019 at 16:25
  • I see , thanks for the input.
    – Elbasel
    Oct 8, 2019 at 19:45

2 Answers 2

6

If the syntax errors are irrelevant to the question, use a comment to point them out. If the syntax errors render the question nonsensical or confusing, vote to close the question.

3

Well, what I would do - indeed, have done, on occasion - is add a 'comment' if possible when I post an answer to the original question. So, for example, if a user posted this code:

#include <iostream>
using namespace std;
int main()
{
    int n
    cout << "Enter a number: " << endl;
    cin >> n;
    do {
        n /= 2;
        cout << "Half of number is: << n << endl;
    } while (n >= 0);
    cout << "Done!" << endl;
    return 0;
}

And had asked why the loop was running for ever, then I would explain that the problem was the comparison, n >= 0 is always going to be true and I would offer a fix, posted as a 'working' code section.

In that posted code, I may also add some other comments, remarks, or suggestions. Maybe like this:

#include <iostream>
//using namespace std; // This is considered 'bad form' (post a link to SO discussion)
using std::cout;  using std::cin; using std::endl; // Better! Only "using" what you use!
int main()
{
    int n
    cout << "Enter a number: " << endl;
    cin >> n;
    do {
        n /= 2;
        cout << "Half of number is: << n << endl;
    } while (n > 0); // MAIN PROBLEM: n >= 0 will always be TRUE! When n reaches 0 it will remain at that value!
    cout << "Done!" << endl;
    return 0;
}

You can see this philosophy in action here.

8
  • Note that we have a close reason specifically for typos. I'm not saying this specific error is a typo (I don't know this language (C? C++?)), but when it is, it's generally better to point out the typo in a comment and vote to close... You can of course expound on other topics in that comment. Oct 10, 2019 at 14:33
  • @HereticMonkey The 'example' I posted was a simplification (possibly over-simplification) just to keep the post brief. Obviously, if that were a real question, I would just post a comment. In the linked (real) question, there were more subtle coding errors, so an explanation and answer were warranted, IMHO. Oct 10, 2019 at 14:36
  • Sure, I just wanted to point out the close reason so that new users don't get the idea that they should be answering every typo question with an answer (something I see a lot of in the tags I follow). Oct 10, 2019 at 14:38
  • Also, note, that I would not use this approach to all questions. In cases where the OP is clearly a beginner/learner of the language in question, then I think it's appropriate. However, in cases where the OP is more of a 'high-flyer', I wouldn't presume to educate on coding style. Oct 10, 2019 at 14:39
  • We close entire topics for a simple typo? This is the sort of thing that makes SO come across as hostile. Oct 13, 2019 at 16:12
  • @ChuckAdams - You said "Hostile!" Careful what you wish for!! Oct 13, 2019 at 17:43
  • @chuck. Simple typo Q's have no lasting value for future readers. Pointing out the typo in a comment and closing as typo is helpful, not hostile Oct 14, 2019 at 12:33
  • I had taken that as closing a post merely because it contained a typo, which is beyond crazy. Apologies. Oct 14, 2019 at 12:47

You must log in to answer this question.

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