Machines have less problems. I’d like to be a machine, wouldn’t you?
Andy Warhol*
Programming code created by others can (and most often should) be used either as part of you code or as examples or material in your writings. The general rule is that when you use code written by someone else, appropriate credit should be given.
It is the responsibility of the author (e.g., the student) of a paper/report/thesis to ensure that all necessary permissions have been obtained and/or the appropriate credits are given in the text before the paper/report/thesis is published or submitted for examination.
There is no need to make a reference to your own original work created for the project being discussed. However, if your code is previously published in e.g., a repository, a link can and (in the case of the material already being published) should be correctly referenced in the text and in the reference list.
Hope you find this material useful!
If you are looking for other resources around writing to use, here is a page with resources and material. If you are looking for how to use and cite figures, screenshots, code etc. please refer to the following documents: How to use and cite figures from other sources, How to cite screenshots, References to secondary sources and review articles, Writing references to personal communication, Writing references to programming code, and Citing content created by generative AI. Regarding quotes and visualizing data, please read the following documents: Master quotes in writing and How to visualize your data in an understandable way.
How to cite computer code
These guidelines are loosely based on the following sources:
Writing Code by MIT
Citing Programming Code by University of Arkansas
Citation File Format (CFF) by GitHub
Programming code should be treated as any other published source. Meaning that if you refer to code in a publication, you should use an ordinary reference in the text and have it as a post in the reference list. Just as any use of published material. If you quote code (meaning that you use e.g., a snippet of code in your text), it should be treated as a quote, i.e., you cite as mention above and add page numbers to the reference (if page numbers exist).
The information that should be given in the reference list are: Author(s), title of program/source code, the version of the source code, and the location (if available on e.g., a website or in a repository).
Example (name, year):
The code written by Mejtoft (2023) was used when extracting the data.
...
The following code is an example of how to extract information from a database (Mejtoft, 2023, p. 23): ...
Reference (APA):
Mejtoft, T. (2023, May 9). Super database extraction (version 0.45) [source code]. Available at http://www.mejtoft.se/thomas/
Example (numeric):
The code written by Mejtoft [13] was used when extracting the data.
...
The following code is an example of how to extract information from a database [13, p. 23]: ...
Reference (loosely based on ACM):
[13] Thomas Mejtoft. 2023, May 9. Super database extraction (version 0.45) [source code]. Available at http://www.mejtoft.se/thomas/
When a snippet of code is cited in text, writing the reference in a similar way as referring to a table is best practice. This means that (most often) a reference with page number (if available) in the description and the description should (most often) be above, since it is treated as table.
Example (in-document listing):
Listing 1: File loading algoritm in PHP (Mejtoft, 2007).
function load_ip_list($file) {
$fp = fopen($file,"r") or die("Problem: $file");
$ips = fread($fp, filesize($file));
fclose($fp);
return $ips;
}
Please note that when code is used in a document it should be labeled, just as any table, figure, or equation. Code is usually labeled as "Listing"
with an appropriate Listing text (see example above).
Just as giving credit in a document, credit should be given in the source code if others’ original work is used.
Example (in-code citing):
%Title: <title of program/source code>
%Author: <author(s) names>
%Date: <date of current version>
%Code version: <code version>
%Availability: <location of the source code>
If you use code from a repository, there might be indications on how to cite the source. GitHub are using a Citation File Format (.cff
) files for information about how to cite code form a repository. You can read more about .cff
files here.
Even though not generically supported in BibTeX, the @software style can be used in several templates to create entries for source code or software that are going to be referenced. Read more about using references using BibTeX here.
Even though there are some cases where it is stated that no credit is needed for the use of an original work (so-called public domain works), a note about the original author (if it is known) should always be included when using public domain works in publications or on websites to give credit to the original author/designer/creator! In other words, always use one of the examples above.
*Quote by Andy Warhol, quoted in the book published on the occasion of the Andy Warhol exhibition at Moderna Museet in Stockholm February-March 1968 (Warhol et al., 1968).
Warhol, A., Köning, K., Hultén, P., & Granath, O. (Eds.) (1968). Andy Warhol: publ. on the occasion of the Andy Warhol exhibition at Moderna Museet in Stockholm, February-March 1968. Moderna Museet.
Cite this page as (APA style):
Mejtoft, T. (2024). Writing references to programming code. Retrieved from https://www.mejtoft.se/thomas/education/academic-writing/writing-references-to-programming-code/
(First published by Thomas Mejtoft: 2023-05-09; Last updated: 2024-09-06)