16

Is it all right to paste a long bit of source code and ask the community to find the bug in it? (Naturally also describing what is wrong with as well as possible and including any compiler errors etc.)

I have a thing that I am working on in a new language and I am unsure if Stack Overflow is intended for requests like "here is my code, please figure out what's wrong with it". My code will not compile and I cannot tell from the error messages and the documentation what I'm doing wrong.

Is Stack Overflow the right place to go in a situation like this, or would someone stuck like me have to go narrow it down and then come back to ask a more specific question?

1
  • Does SO discourage discourage duplicate verbs? :-)
    – SLaks
    Commented Jan 28, 2010 at 15:30

4 Answers 4

20

Generally, it's a bad idea to paste in a big block of code like that. Many people on Stack Overflow won't really bother giving it more than a cursory glance. Sometimes you'll get lucky and someone will be able to take a look and tell you the problem at a glance, but that doesn't always happen.

These types of questions also aren't as valuable to other programmers who might be searching for a similar problem. Because the line with the error will be buried deep within the question with lots of extraneous material, it will be hard for someone else searching for the same problem to tell if your question is relevant to them.

A good technique for getting better answers, and even solving your problem yourself, is to try and isolate the problem by removing more and more code until you have a minimal example that gets the same error. In the process of doing this, you may even discover the problem yourself (once you've isolated it down, it sometimes becomes apparent immediately what the problem is). Even if you don't, you'll now have a short example, that experts in the language in question may be able to eyeball and see the problem, or at least will be able to download it, try the code themselves, and perhaps isolate the problem that way.

I'd recommend trying to stay away from big blocks of code with "please find the bug" attached.

11

Does SO discourage discourage questions like “this is my code, please find the bug”?

Yes.

Is it alright to paste a long* bit of source code and ask the community to find the bug in it?
* Emphasis mine

No

I have a thing that I am working on in a new language and I am unsure if Stack Overflow is intended for requests like "here is my code, please figure out what's wrong with it".

Generally, no.

My code will not compile and I cannot tell from the error messages and the documentation what I'm doing wrong.

Create the smallest example you can replicating the error. Don't just post a big source file and expect to get consulting for free.

Is Stack Overflow the right place to go in a situation like this, or would someone stuck like me have to go narrow it down and then come back to ask a more specific question?

Yes, in SO pleads for help on specific problems is not discouraged, but don't just dump a source file and ask "I get error. Plz help." as you'll get closed as fast as you can say "Not a real question".

If you show that you made due diligence and have put some effort in figuring out the problem yourself, provide enough information, while still keeping it short, the comunity will try and help you.

1

You can ask such questions on Code Review. It's a new site, it probably wasn't there when you asked the question.

1
  • This is unfortunately incorrect. From Code Review's FAQ: «If [...] your question is not about [...] •Trouble-shooting, debugging, or understanding code snippets [...] then you are in the right place!»
    – jscs
    Commented Jun 3, 2011 at 2:43
0

If you really have no clue what the problem is in your code, you need to learn good debugging techniques.

The main technique applicable to your situation is to narrow the error down. In many situations the easiest way to do that is to comment out sections of code until the error no longer occurs. Then uncomment the last section you 'removed' and start commenting out lines of code in that section until the error goes away.

Even though the compiler reports an error, and a line number, you can't be certain that the problem actually occurs on that line, only that the compiler detects there's a problem once it got to that line.

Now comment out all the other code that's not necessary to make the error happen.

Whatever is left is hopefully a very short piece of code that demonstrates the error.

If you are still stumped, post that small snippet of code, the error you're getting, and a short blurb explaining what you've done so people don't think you're just asking for a handout with no effort.

If you still need help, search SO for debugging techniques.

You must log in to answer this question.