Would a question asking primarily for sample code (to be studied for comprehension, and possibly reused), rather than for a working program or library, be on-topic?

On the one hand, asking for sample code for an interface or algorithm is more like asking for a tutorial about that interface or a reference book about that algorithm. This isn't what we do here.

On the other hand, that sample code is supposed to accomplish some task (implement an algorithm, or whatever). So it is software for a particular purpose, which is what this site is about. There just happens to be a requirement that the software's source code be available and illustrative.

Example: https://crypto.stackexchange.com/questions/18063/trapdoor-permutation-hardcore-predicate

I'm trying to understand the basic scheme of deniable encryption (…). Is there any source code example (c/c++) on trapdoor permutation or hardcore predicate that I can use as reference? Both are implemented in deniable encryption. Also, is there any source code example on deniable encryption (for reference)?

  • On which other S.E site could one ask? Would such a question be acceptable on programmers?
    – Mawg
    Jun 5, 2015 at 8:38
  • @Mawg Stack Overflow, if anywhere. Definitely not Software Engineering. Jun 5, 2015 at 9:45
  • Are you sure? S.O requires that you have code, post it, explain what it ought to do, and how it is going wrong. You example is fine on crypto, but what about questions like mine, where I want some "bad code" to use to validate static code analyzers? softwarerecs.stackexchange.com/questions/20074/… surely wouldn't last 2 minutes on S.O before it was closed. On programmers, I feel that I could ask for a general approach to validating static code analyzers, but am not sure about asking for actual source code.
    – Mawg
    Jun 5, 2015 at 9:51
  • 1
    @Mawg Yes, it can be tough getting anything other than “debug my code” through on SO. In principle, “code to exercise a specific point” would be on-topic. But that isn't what you asked here: you're asking for a whole code base, not for a code sample. Asking for a whole code base is borderline here, it's somewhere between software (on-topic) and a data source (off-topic). We already have a thread about that, but your case isn't exactly the same, please start a new meta thread. Jun 5, 2015 at 10:04

1 Answer 1


I would feel no except in the context of describing something that's part of the answer - for example, illustrating how a specific language/compiler combination solves a specific issue, or likewise with a library. I'd think that code related questions are best left to SO and other programming specific sites.

Questions shouldn't ask primarily for code - they should ask for software (or by extention libraries) that solve a problem, and the code might be a way to add to the answer.

  • My feelings exactly - I was struggling with how to write it in an answer.
    – user46
    Jul 11, 2014 at 1:18
  • So summed up: "It's fine to do so, but please on a different SE site"? Agreed then :)
    – Izzy Mod
    Jul 11, 2014 at 13:22
  • Oh but this is true of anything. Its fine to ask questions about your cat. Just not here, if it dosen't involve a software req ;p Jul 11, 2014 at 13:47

You must log in to answer this question.

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