What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 150 Stack Exchange communities.

Very frequently new users will respond to your answer with a comment containing a gigantic unreadable block of code that clarifies some detail. This code should ideally be edited into the original question.

I think it would be a good idea to display a notice suggesting that code be edited into the question if all of the following are true:

  1. The person leaving the comment is the owner of the question
  2. Code in the comment exceeds a reasonable number of characters
  3. (Optional) The user's rep is under a certain threshhold

Since there seems to be some confusion, please note that this measure would not somehow outlaw all code snippets in comments. It only applies to unreadably long code snippets.

In fact, it doesn't even ban the code snippets it is targeting, since the notice will be dismissable. All this does is inform the commenter about the correct place to post their code, so other users don't have to.

Suggestions/improvements welcome.

EDIT: Since people seem to agree with the idea I am going to upgrade this to a feature request.

Here are some occurrences of the problem:

I will add more as I find them.

share|improve this question
Rule of thumb: users, especially new, do not read notices. Period. No matter how many you will put in front of their eyes and how big, they will just keep ignoring them. So even though this suggestion is good, I can assume for almost 100% of certainty that it won't help in the end of the day. Comments from actual users get more attention, so in my opinion there's no choice but keep nagging such users with comments. –  Shadow Wizard Nov 25 '12 at 11:05
@ShadowWizard So you are saying that I also shouldn't add moderation comments like "Please add the code to your question by editing it"? They'll notice the downvote though... –  oberlies Jun 5 '14 at 12:07

2 Answers 2

Add a comment to the question, to the effect of "Please don't put code in comments; it is impossible to read. Edit the code into your question instead."

If the code in the comments seems reasonably complete, and you have editing rights, you can help the OP out by editing the code into the question yourself, and flagging for comments removal.

In other words, it's a little more complicated than just putting up a notice.

Folks put code in comments pretty often, and it works, provided the code is kept very, very short. I'd hate to have to see this warning every time I notified a poster of a minor error in their code by noting the correction in a comment, and I prefer doing that than correcting the poster's code myself.

share|improve this answer
You seem to have missed the requirements that the code be over a certain number of characters, and that the commenter be the owner of the question. If you have a contiguous block of code over 200 characters long there is a problem, and a dismissable notice will not be out of place. Minor corrections to a posters code would not trigger warnings. –  Asad Saeeduddin Nov 24 '12 at 9:18
@Asad: For a new feature to justify the cost of its implementation, it needs to be something that solves a significant problem that is broadly applicable to the community. I don't think this feature meets that bar. Just leave your own comment explaining the problem. –  Robert Harvey Nov 24 '12 at 19:45
The issue I have with commenting is that it generates its own noise. First you have to leave a comment with an explanation, then you have to flag the asker's comment, then you have to edit the question with the code from the comment, then when the OP's comment is removed remove your own. Why not prevent all of this hassle? Do you feel I would have a stronger case if I were to provide several examples of this happening from the past few days? –  Asad Saeeduddin Nov 24 '12 at 20:01
This is a really necessary feature. –  rob.alarcon Dec 19 '12 at 19:13

I do not know whether this would be a new question — but it would seem that this issue should be cross posted with Multi-line comments on Stack Overflow.

If you do think that this should be a new question, I have expanded it to a full new question here to actually include details that are not directly relevant to this local concern. Currently there is no system for properly formatting code left in comments. I have to point out that if the consensus is that code in comments is ever useful, even if the goal is to dissuade people from posting long chunks of code into comments, wouldn't it be desirable to have proper line-breaks and other simple formatting options (optional syntax highlighting) for code snippets that are not too many lines long.

New python executables in MYENV/bin/python3.4 
Also creating executable in MYENV/bin/python 
Installing setuptools, pip, wheel...done.`

is much easier to read than `> New python executables in MYENV/bin/python3.4 > Also creating executable in MYENV/bin/python > Installing setuptools, pip, wheel...done.`

And I'd much have preferred to write that (here). And it would not have taken up much more space compared to other comments. So legibility suggests that better formatting for those shorter code snippets should be desirable if it is recognized that code snippets should be well designed.

Furthermore — that concern – I'd argue – should win over a theoretical concern raised in the crosslinked post which shifted a discussion about multi-line comments to the appropriateness of including code in comments in the particular case where you are writing modifications of example code from the post. However, this use case does not cover all the kinds of instances where code formatting would be useful.

From the perspective of this question's point of not wanting to encourage long comments filled with illegible code that skewed the display of the comment section, you could put an upper limit on numbers of lines allowed (at least 5 total would make it no longer than the max of the current comments), and if the warning is instituted in the form as it is described here, it could additionally warn people if they exceed some threshold of character density.

So in that sense, it seems like this warning is worthwhile, however, for the things that don't trigger the warning, there should be a better method for formatting them. Currently they are far too hard to read. Scaling Consolas down to 11 pts might make it a little hard to read…

…but I will leave those details and related concerns to the other question that I'll ask here (link to come).

But I do believe that the answer I provide here is providing a unique, relevant set of insights that answer this particular question at large which is regarding how to prevent unreadable segments of code in comments. It is relevant because it provides a further provision regarding the kinds of situations that will be needed to be considered as part of the described warning for difficult to read code snippets.

And certainly if we are to consider with any prejudice the perspective induced from the title as being the abstract "code in comments", I think we all can agree that the concern about how we format that code which is sanctioned by silence (non-warning) in comments is almost surely relevant to the general concern of code in comments. If this is not intended to be a general discussion of those policies, I think there should be a change to the title to better reflect the exact content intended for this discussion to proceed.

Also it is unclear whether this information has been updated to account for any features actually implemented regarding this discussion, since that request for a feature seems to have been made ~2.75 years ago. If anything has been implemented regarding this, it would be good to see it expressed in the original question.

share|improve this answer
I think it is a new question since this FR is just to show a notice. That makes this NAA to me. –  Patrick Hofman Aug 4 at 9:06
I recognize that — but I'm saying that if feature request in the new question that I've now posted and will link to is accepted, this will have ramifications for the present discussion about when to issue the notice regarding the continued legibility of comments even if code-formatting is included. Thus it is part of the feature request, to be extended to a more subtle notion of when to raise the notice(if not more than a notice). –  mpacer Aug 4 at 9:15
This doesn't address the FR for the notice at all. So still NAA. –  Patrick Hofman Aug 4 at 9:44
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. –  Deer Hunter Aug 4 at 9:54
If you believe that this is irrelevant, then title of the post should be changed as this is not a post about "code in comments", but specifically about whether a "notice should be raised if strings of inline code in comments are too long ". I don't know how to suggest a title change, but I know it can be done. –  mpacer Aug 4 at 9:58

You must log in to answer this question.

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