In this question, the guy pasted 150+ lines of code when the issue was with one specific line.
Is it legitimate to edit his question and keep only that single line?

The line:

Nullable<DateTime> lastPostDate = (reader[3] == DBNull.Value ? null : Convert.ToDateTime(reader[3]));


I'm asking on a scenario where there is no doubt. The relevant code is this line and this line only.

  • 2
    Well, if I only read that line, would I immediately know what's wrong with it? Was the original code a minimal working example?
    – slhck
    Feb 7, 2012 at 8:39
  • 1
    @slhck. Yes that line is enough, The original code was a MAXIMUM working example...
    – user173320
    Feb 7, 2012 at 8:39
  • 2
    I'd be very cautious about removing any code from a question. While it is tempting, I've often seen cases where the problem lies quite a few lines from the code the OP highlights.
    – ChrisF Mod
    Feb 7, 2012 at 9:00
  • 1
    anything that brings code snippet closer to SSCCE looks safe to me. Anything else is generally under suspect
    – gnat
    Feb 7, 2012 at 9:18

3 Answers 3


Yes, probably.

I can't answer for your specific question as I don't have enough experience in that tag to know if it is a legitimate edit, but I'm active in the iOS tags and quite often people post the entire implementation of a class, including all the boilerplate comments and default method stubs added by the IDE. I happily remove all of this because it makes finding the code the questioner has actually written and has a problem with much easier.

Of course, there are caveats - you have to be confident that you really aren't removing anything relevant (perhaps a comment to say that you have removed default implementations or something?) and you have to leave enough context in there so the question makes sense to a reader coming to it for the first time.

Irrelevant code is no different to irrelevant prose in a question. Lose it.


If you ask me, the answer is no and I will try to explain why.

Code has special "stance" in my opinion:

  • It's not bound to readability or grammar rules like ordinary post contents.
  • One small change in code might cause huge impact and render the whole post useless.
  • It's under the responsibility of the post author, and his/her alone. If there is mistake in code, nobody should correct that for the author - he or she should do that themselves.

Posting more code than necessary is borderline case - on one hand, it's not wrong code but on the other hand you can't always be 100% sure what is the real relevant part. Maybe the author forgot to mention something in the post, and the code explains this?

And "when there is doubt, there is no doubt" - better play it safe.

Just post comment on the post asking the author to put only the relevant code - that's the best course of action in my opinion.

  • I'm asking on a scenario where there is no doubt. The relevant code is this line and this line only.
    – user173320
    Feb 7, 2012 at 11:42
  • 4
    @gdoron - in that case this question is "too localised". In the general case you should not really edit the code in the question for the reasons Sha Dow outlines. In your specific case it looks like it's OK, but that's only going to be a very small proportion of questions.
    – ChrisF Mod
    Feb 7, 2012 at 11:44
  • @gdoron what Chris said, plus my $.01 - sometimes having more code give better "background" of what's going on and makes it easier to understand the bigger picture. Maybe in this very specific case you're right, but still - posting comment asking the author is the best and safest action. Feb 7, 2012 at 11:46
  • Even though I posted an opposing viewpoint as an answer, I mostly agree with this too. Just goes to show that the answer to any question on meta should simply be "It depends..."
    – jrturton
    Feb 7, 2012 at 14:23

Could it be usefull to edit parts like

    this.ForumID = forumID;
    this.AddedBy = addedBy;
    this.AddedDate = addedDate;
    this.Title = title;
    this.Description = description;
    this.ParentID = parentID;
    this.Moderated = moderated;
    this.ImageUrl = imageUrl;
    this.UpdatedBy = updatedBy;
    this.UpdatedDate = updatedDate;
    this.Active = active;
    this.ForumGroup = forumGroup;
    this.ThreadCount = threadCount;
    this.LastPostBy = lastPostBy;
    this.LastPostDate = lastPostDate;
    this.LastPostTitle = lastPostTitle;


    this.ForumID = forumID;
    this.LastPostTitle = lastPostTitle;
    // More setters here (but removed for readability)

as this approach does not remove code that is related to the actual problem.It does provide more readability. And we can assume that in that case all the other setters are invoked in the actual code.

You must log in to answer this question.