0

On Stack Overflow, many people are asking questions with the following type of programming code:

a = 123;
b = 345;
// g = funGet(a,b); // COMMENT
g = a + b;

When editing the question (for improving the question), should we remove such comments? Are there any guidelines for it?

3
  • 6
    Why would you remove them?
    – Bart
    Commented Dec 10, 2012 at 7:10
  • Sometimes the commented lines are more than uncommented lines, for improving the readability of the code.
    – user181512
    Commented Dec 10, 2012 at 7:12
  • 7
    I would only remove them if they are clearly not related to the issue at hand. But usually, they are; often people will put in comments that specifically address the question, or comment out a line that was important in their debugging. Commented Dec 10, 2012 at 7:12

2 Answers 2

10

I don't think there are any strict rules about this or that we could realistically come up with some.

My personal guideline is that if there's a lot of commented out code and it makes it harder to read what's going on, I remove it. If it's just one or two lines? Meh.

Either way, you gotta be careful, because sometimes folks will leave commented out code in their samples to show what other things they've tried. Clearing those out could hurt. So, it really depends and I look at each case individually.

1
  • 2
    There's also the extreme case when a comment is the problem, i.e. the poor sob has commented out their code by mistake (multi-line comments can be evil like that). I've seen this once on SO, once on MSO and countless times in my own code ;P
    – yannis
    Commented Dec 10, 2012 at 7:34
5

I don't really see any reason to do so, and I'd generally avoid it just in case. If you are absolutely, 100% sure that the commented line has absolutely nothing to do with the question, go ahead and edit it out. But you have to be 100% sure, not 99.99999%.

Keep in mind that if you suggest an edit like that, it's very, very likely to get rejected, simply because changes to a user's code tend to be incorrect, and people don't usually look past that. Combine that with the fact that it's very minor.

So, to summarize: you probably should just let it go. Most people won't even include random comments like that unless they're relevant to the question. If not, it's one line; no big deal.

1
  • Of course, this doesn't mean you couldn't fix other issues in the post while also removing the clutter. ;)
    – jmort253
    Commented Dec 10, 2012 at 8:33

You must log in to answer this question.