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

Each programming language has its own quirks, and often there emerges code patterns in the community which is collectively founded on an enormous amount of experience. Many of these patterns are highly counter-intuitive to someone new to the language (For example, quoting in Bash). Many questions on SO include code which could be made more readable, secure, reliable or otherwise "better" according to current consensus by following such patterns, but it's not a solution to the question posed by the OP. It's not a given that such advice should be introduced in SO, but it could potentially improve the overall quality of the code produced by the community, while fostering the exploration and discussion of new and existing patterns to improve even further.

There are several things one could do with questions which don't follow an established pattern:

  1. Add an answer with advice or improved code. This is terrible, since it's not an answer to the question.
  2. Add a comment. Less visible, but can't be removed after the timeout even if the code is improved. And like adding an answer, it doesn't actually improve the all-important code in the question.
  3. Modify the code in the question. While this could improve the question by allowing more direct focus on the problem at hand, it could also make the code longer, and there's the possibility for edit wars if the pattern is not universally acknowledged.
  4. Contact the user directly. This is not generally possible, and would in the best case only help one user.
  5. Keep it to yourself, and wallow in the code of a thousand noobs.
  6. Modify the code in the answer, after verifying that the changed code still answers the question.

IMO the last option is the best, since it improves the overall usefulness of SO (if applied judiciously) at the cost of moderators' time only.

What is the SO community position on tangential advice?

share|improve this question
    
If you can answer the question, answer it and provide notes as to the other tangential issues. Otherwise, if you see a good answer, you can edit it and add this kind of information. Definitely comment if either of those options are not appealing. –  Oded Dec 21 '11 at 13:19

3 Answers 3

up vote 12 down vote accepted

Never modify the code in the question.

Even if it's just to "improve" the readability.

The code is what the OP has that isn't working. What ever is wrong with the code could well be the source of the problem. Editing the code could remove the source of the error and thus invalidate the question and any existing answers.

If you are concerned about good practice etc post a comment pointing out where the code could be improved. If it's really serious and it is the source of the problem post it as an answer.

share|improve this answer
    
Good point. How about if you can see that it doesn't interfere, for example if a working fix has already been posted or you can verify that the problem persists after modifying the code? After all, some modifications could make it more obvious where the problem is. –  l0b0 Dec 21 '11 at 13:23
3  
@l0b0 - I'd still steer clear of modifying the code. –  ChrisF Dec 21 '11 at 13:24
    
Changed my opinion based on this answer. –  l0b0 Dec 21 '11 at 13:35

Whenever I find myself doing this, it's often as an addendum to the answer. I feel that giving a little more advice, while not directly improving the answer in any way, does provide that much more help to the user. Additionally, it can be equally helpful to someone who stumbles across the same question/answer in the future.

In most cases with my answers it's something as simple as this...

What you're trying to do can be accomplished with [insert advice here]. Something like:

[insert code snippet here]

A few things to note about this code and how it works:

[insert some notes here]

Additionally, just as an aside, note what I did with the variable names. In C# it's considered more canonical not to begin variable names with a capital letter, and to reserve that for class names and other such things. Generally a lowercase letter is preferred, or an underscore (depending on personal style, I like to use underscores for private members). Note how the code formatting in your question mistakenly highlighted the variables as classes. This is because the code formatting library used on this site assumes this convention in C#.

It's simple, it's not a big deal, but it's just a little extra advice to try to help the OP and/or anybody else who happens along. After all, we all know that the code snippets we leave here will someday be copied/pasted into some beginner developer's production code without any knowledge of what it's actually doing. They just "found a script online that fixes the problem." So it's worth that little extra effort to improve the code in the Q&A thread as much as possible.

share|improve this answer

A canonical example of when we point out things that aren't strictly in the question but are very clearly a problem if the asker continues along that path are vulnerabilities for SQL Injection. When the user is appending input into a SQL statement, we are often compelled to point out the vulnerability and perhaps send them off on a hunt for information on parameterized queries. We can normally get our point across in a very simple comment or, if we're already answering the main point of the question, a statement about the vulnerability in our answer. If the code leads us to it, we might even include an example if it fits within the overall answer, as well.

These things happen organically. They do not need a convention or some community wide effort, they just happen, and they generally fit within the standards that have been established on these sites.

With that in mind, do not modify the code in the question, that's potentially changing the meaning. Do not just provide an answer that doesn't address the main thrust of the question, that is adding noise not related to the actual problem. Do provide a succinct comment if you feel like there is an issue the user needs to know about, either to the question directly or inside your otherwise valid answer.

share|improve this answer

You must log in to answer this question.

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