My question includes a code snippet from an open-source library. The snippet is used to illustrate what I believe may be poor programming practice, as relevant to the question. As I don't want to point fingers, would it suffice to say that the snippet comes from "a Scala numerical library"? Or should I give the full reference, eg, as required in an academic paper?
1 Answer
There are different aspects to this question: what your legal and ethical requirements are, and whether you should ask a question about someone else's code.
Legally, you probably do not have the right to post that code here under the CC-BY-SA 3.0 license, unless you can rely on some copyright exception in your jurisdiction (e.g. fair use, or a right to cite). A citation must be accompanied by a source, e.g. a hyperlink. If you do not want to cite the code verbatim, you can always paraphrase it.
Ethically, the standards of academic conduct do not apply on this site. E.g. you are not required to provide references for non-original ideas. This doesn't absolve you from possible legal requirements to provide a source for a citation.
Whether “pointing fingers” would be an ethical problem, I don't think so. If you are citing published code, that code already was publicly available and you are merely drawing more attention to it. A lot depends on what kind of question you are asking. An on-topic, respectful question asked in good faith should not be a problem.
Note that the Code Review site explicitly forbids asking about other people's code for a variety of reasons, including licensing concerns as they require the complete code to be included in a question, not just a snippet; ethical concerns as the site is about (constructive) criticism; and because of the goal of that site: self-improvement.
Are questions about other people's code acceptable here on Software Engineering? In general, NO.
Questions work best when they are about a concrete problem you are having.
This site is about Software Engineering, in particular design and architecture concepts. Code-level questions are off topic.
Questions that ask for best practices are off topic. As there is frequently no industry-wide best practice, any answers tend to be personal opinions.
Questions that ask us to explain someone else's decisions are off topic. In particular, questions along the line “Why was the code designed like this” are unanswerable except by the original author.
Conversely, this means that showing someone else's code can be fine under some circumstances.
You have your own question, and merely use someone else's code to illustrate and support that question. I.e. the code should not be the subject of the question.
You have stripped down the code to its relevant aspects. Frequently, domain-specific details or whole method bodies can be removed. Formatting can be simplified to emphasize the structure. There is no expectation that any shown code actually compiles.
Consider whether showing real code is best, or whether a different representation like pseudocode or a diagrams would be clearer.
One of the best descriptions of the Software Engineering site is Jeff Atwood's description in the graduation announcement:
In a nutshell, Stack Overflow is for when you’re front of your compiler or editor working through code issues. [Software Engineering] is for when you’re in front of a whiteboard working through higher level conceptual programming issues.
The whiteboard metaphor works very well to get a feeling for whether you should show any code (your own or someone else's) and how much: Prefer to show code only in that detail that you would scribble on a whiteboard while discussing your concrete software engineering problem with a colleague.