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

I see a lot of questions here with inexact code snippets, where the questioner obviously re-typed or summarized the code that's causing the problem. This can make it difficult to distinguish between errors in the original code and errors that the poster introduced by re-typing the offending code. For example, I recently read a question about the behavior of the posted code, but it was missing a semicolon and so would not compile.

The result tends to be that we have to go back and forth clarifying what the real code looks like before we can solve the problem. (Or, in some cases, somebody manages to make a lucky guess.)

In my opinion, we should strongly encourage questioners to copy-and-paste the exact code that they're asking about. Ideally, they should reduce their code to a small, self-contained program that exhibits the problem. If it's a run-time problem, the posted code should be compilable. Error messages should also be copy-and-pasted, and if they refer to line numbers, there should be a comment in the source indicating the referenced line.

If there's something about this in the FAQ, I failed to find it.

I'll usually post a comment asking the questioner to post the exact code, but is there something more general we can do? My suggestion would be to add a paragraph to the "How to Ask" page encouraging copy-and-paste of source code.

I might also suggest a link to Eric Raymond's "How To Ask Questions The Smart Way", though it may be too much to expect most questioners to read all of it.

share|improve this question
3  
I really don't want to see walls of code. –  NullUserException อ_อ Oct 6 '11 at 20:01
2  
@NullUserExceptionஇ_இ: Which is why I said the ideal posting would contain a small, self-contained program. Sometimes code fragments are perfectly appropriate (but even so, if you don't know what the problem is, it's too easy to leave out the relevant code). How would you address the problem of someone asking about the run-time behavior of a program, and posting code that won't even compile? –  Keith Thompson Oct 6 '11 at 20:05
    
Not really an answer -- which is why I'm using a comment -- but you might be interested in meta.stackexchange.com/q/18584/131713 and meta.stackexchange.com/q/92074/131713. Both are [faq] entries that reference HTAQTSW. –  Pops Oct 6 '11 at 20:11
    
@KeithThompson: You shouldn't have to compile a code snippet to answer a question. If you have to, they aren't giving you enough information or they need to clean up their code badly (which is probably why they can't get stuff to work in the first place). –  Won't Oct 6 '11 at 20:22
    
@Won'tಠ_ಠ: Perhaps not, but I should be able to read the code. I'm not advocating the posting of messy code, quite the contrary. –  Keith Thompson Oct 6 '11 at 20:26

2 Answers 2

We should be encouraging people to create prototypes that reproduce their issue in the least amount of code possible. This way they not only will be able to create concise questions with the minimal amount of code that demonstrates their issue, but they might also find the solution to their problem in the process. I know I have. On several occasions.

Pasting code from your actual program always results in the code snippets being full of pointless crap that only serves to push the real issue beyond the scrollbars and make the question practically unreadable.

If I see this one more time (example is in xaml)...

<TextBox Grid.Column="5" Grid.RowSpan="2" Grid.Row="4" Background="CornflowerBlue" Foreground="LightGray" ScrollViewer.VerticalScrollbarVisibility="Hidden" Click="SomeStupidForm_Click" FocusManager.IsFocused="true" Herp="Derp" Text="{Binding ThisIsWhereTheRealIssueIs, ElementName=Nonexistant}" />

Not only is this the optimal course of action, it is usually the only practical (in terms of getting an answer) one. Encouraging users to do otherwise should be considered harmful.

share|improve this answer
    
It doesn't always result in pointless crap -- or at least it shouldn't. –  Keith Thompson Oct 6 '11 at 20:27
    
@KeithThompson: Okay, 80% of the time. IMHO its just about that bad. Also, did you notice the bug in my code snippet? You don't have to know anything about xaml or xml to figure out where the hypothetical problem lies. Scroll to the very end and read. If this were a real problem and a real snippet, I'd have already moved on just like you did... –  Won't Oct 6 '11 at 20:52

Just downvote it and vote for close as Not a real question and move on to the next (hopefully viable) question. Don't waste too much time (and stress) on this kind of users. If they really needed quality help, they'll realize that themselves sooner or later.

share|improve this answer
    
I'd much rather encourage them to post good questions in the first place. A lot of people honestly don't know this stuff. I'd rather educate them than punish them for not already knowing it. (Yes, "punish" probably overstates the issue.) –  Keith Thompson Oct 6 '11 at 20:23
    
Maybe we have had a different share of users in mind. If they explain the problem very well with clear functional requirements and clear problem descriptions, but just post bad/incomplete code, then I'd definitely also comment them on that. But other than that, I'd downvote/close it. But usually, I see that kind of code more than often in combination with a badly formulated question which is at its own unanswerable without viable code. –  BalusC Oct 6 '11 at 20:34

You must log in to answer this question.

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