Not all code needs to be cited. Which code needs to be cited and which code does not needs to be cited will be covered in the next two chapters.
For now, let’s say we have found some code online that we would like to use in an assignment. Let’s also assume that a. the code snippet falls under the Creative Commons; and b) the assignment permits the use of code samples. So how do we cite a code snippet?
In your source code, directly above the snippet of code that requires a citation, add a comment including:
.
Not the First [Digital Image]. 2019. Retrieved from https://www.reddit.com/r/ProgrammerHumor/
Below are a series of citation examples. The examples include a variety of different languages as the syntax for commenting varies.
For future reference, the three examples below are considered coding examples, not documentation. The differences between documentation and examples is crucial and will be outlined in the next few chapters.

https://www.w3schools.com/howto/howto_css_center-vertical.asp
Below is an HTML and CSS code snippet copied from W3Schools. This code centers a div element horizontally and vertically on a web page:

https://www.w3schools.com/howto/howto_css_center-vertical.asp
Note that if the HTML and CSS were placed in two different files, they would both need to be cited separately.
Code from W3Schools is free to use and manipulate. It has been released under the Fair Use License. More information on the terms of use is available on the W3Schools website.

https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript
Below is a JavaScript code snippet copied from StackOverflow. This code defines a function that validates an email address:

https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript
Subscriber content from Stack Overflow is free to use and manipulate. Attribution must be included in your source code and you must share any improvements made to the original code. Subscriber content follows the Creative Commons Attribution-ShareAlike (CC-BY-SA) License. More information on the terms of use is available on the Stack Overflow website.
.
https://pybricks.com/ev3-micropython/examples/robot_educator_line.html
Below is a Python code snippet copied from Pybricks. This code causes a LEGO™ EV3 robot to follow a black line:
.
https://pybricks.com/ev3-micropython/examples/robot_educator_line.html
Code from Pybricks is free to use and manipulate. It has been released under the MIT License. More information on the terms of use is available on the Pybricks website.
.
Jr. Developers [Digital Image]. 2019. Retrieved from https://www.reddit.com/r/ProgrammerHumor/
Even if properly cited, you must still make sure the content creator permits copying. Most popular coding resources use one of the following licenses:
If you cannot locate a license, look for the website Terms and Conditions. For example review the terms of use from W3Schools.
Even after reading the Terms and Conditions, it may still be unclear as to whether or not a developer can use code from W3Schools for their own projects. In this case, reach out to the website and ask. After a few email exchanges with W3Schools, I had the following questions answered:
In the next chapter we will review the use of online coding documentation and how to incorporate code from these sources into student work.
Previous Chapter - Home - Next Chapter