When writing code, you want to use similar citation ideas as in academic writing instances. Whether you are copying or adapting code from a small snippet or using an entire module or function, you must cite your source.
Your citation should include:
- URL of your source
- Date you retrieved your source
- Title of the program or application you are using
- Type (eg. source code, application, full program, etc)
- Author name(s) if available
- Code version if available
- License (if the code you copied has a "copyleft" license)
Here are two methods for citing code from a snippet used from http://www.oregonstate.edu/mysource retrieved on December 2, 2020:
-
You can cite your code in your written report or your README file. Here is an example on how to cite code in a written document:
Sample Format: <author name(s)> (<date retrieved>) <title of application/source code/program> (<Version of code>) [<type of code>]. Source Web address or publisher information.
Example: Safonte, D (December 2020) Citing source code (Version 1.0) [Source Code]. http://www.oregonstate.edu/mysource
-
The second method cite your source right within your code using comments.
Example: a good citation can be observed on lines 1-4 below:
1 # Citation for the following function:
2 # Date: 12/02/2020
3 # Copied from /OR/ Adapted from /OR/ Based on:
4 # Source URL: http://www.oregonstate.edu/mysource
5