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 a research paper. 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.
If you are looking for how to cite figures or screenshots, please refer to these documents: How to cite screenshots and How to use and cite figures from other sources.
How to 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, use an ordinary reference in the text and have it as a post in the reference list. If you quote code (mening that you use e.g., a snippet of code in your text), it should be treated as a quote, i.e., you add page number (if a page number exist).
The information that should be given is: Author(s), title of program/source code, the version of the source code, and the location (if available on a website or in a repository).
Example (name-year):
The code written by Mejtoft (2023) was used when extracting the text.
...
The following code is an example of how to extract information from the database (Mejtoft, 2023, p. 23): ...
Reference (APA):
Mejtoft, T. (2023, May 9). Super database extraction (version 0.45) [source code]. Available from http://www.mejtoft.se/thomas/
or
Example (numeric):
The code written by Mejtoft [13] was used when extracting the text.
...
The following code is an example of how to extract information from the database [13, p. 23]: ...
Reference (loosely based on ACM):
[13] Thomas Mejtoft. 2023, May 9. Super database extraction (version 0.45) [source code]. Available from 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 (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. In this case
Example:
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;
}
In a similar manner, credit should be given in the source code if others’ original works are 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 cases where it is stated that no credit is needed, credit should always be given to the original author/designer/creator when public domain works are used in publications or on websites!
(First published by Thomas Mejtoft: 2023-05-09; Last updated: 2023-05-11)