8

I understand the importance of posting code. As an answerer, I find it extremely valuable when an asker posts code.

However... it's not always easy (or feasible) to post code. Sure, if you're a student working on an assignment, or just working on a small side-project, it's easy to include all the context necessary and post as much as you need to for the question.

But a lot of askers work for companies that have proprietary, confidential source code. Posting that code (even something like a namespace or class name) could lead to problems, legal or otherwise. And sometimes it's too difficult or time-consuming to rewrite/obfuscate the code so that it's safe to post on SO.

What should an asker do if they are unable to include source code in their question, for one reason or another?

3
  • 6
    You can always make a 'anonymised' version of the code. Do test it first, but names are just names and can always be changed. Commented Apr 30, 2014 at 14:52
  • 5
    You would need to provide a small self contained example that reproduces the problem.
    – Lix
    Commented Apr 30, 2014 at 14:53
  • 1
    I would go so far as to say that you should almost never be posting actual production code to this site. Trimming the production code down to the self contained example should always be part of your investigation - in fact that should be done as part of your debugging exercise. So often doing this will mean you don't need to ask the question in the first place. (instances of "you" here are non-specific...) Commented Jul 23, 2014 at 5:51

1 Answer 1

11

If you can't be bothered to generate an example sufficient to have your question answered, then apparently the question isn't sufficiently important to you. What else are you expecting to hear, "It's okay to post a question that doesn't have enough information to be answered because your code is confidential?" Sorry, but that's just not an option.

If you're in that context you may be more inclined to cut down your code examples to a more minimal sample. Great; so long as it's still enough to diagnose the issue, that helps everyone involved. Removing unrelated code entirely is far more valuable to the site than obfuscating it.

If you're able to ask the question in such a way that it's still answerable, but has no code, then by all means. Such questions are much less common on SO, but they exist.

4
  • 5
    If you're not able to cut your code example down to a minimal example then you don't understand what you're doing in the first place. This should always be what you're aiming for and only include more if you're unsure.
    – Ben
    Commented Apr 30, 2014 at 15:06
  • There are times when just TRYING to make a good question, cutting down to the code to be a little more generic, will actually SOLVE the problem, so that's good advice all-around.
    – TecBrat
    Commented May 5, 2014 at 17:46
  • @TecBrat Of course, that's the point. You'll find that the vast majority of guidelines for how to ask a good question are actually guidelines for how to solve your own problem, but in disguise. That's not an accident. It's one of the reasons why you see so few really good questions; the vast majority of good questions get solved by their author before they hit "submit".
    – Servy
    Commented May 5, 2014 at 17:49
  • 2
    @Servy You're forgetting that today's (as opposed to 2008's) SO users don't appear as interested in improving their programming skills as they are patching up someone else's code for a deadline. I can't imagine the mindset of someone who'll post some code and say something like "why is this getting stuck in a loop", but here we are.
    – user146043
    Commented Jun 12, 2014 at 22:59

You must log in to answer this question.

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