How to properly cite a source in code

For example, if one researched how to deep copy a map container and paraphrased a solution from a website, what is the proper format? Are there standards for citing works in code?
I am currently only citing the link to the source in my personal code and explaining what algorithm the source contains, but I really want to avoid heartache in the future if I ever do take part in professional programming.
I have seen documents cite the source and author if there is one named (a person will have their name associated with their code if it is worth citing usually). It is only worth citing a source if the code is very novel or intricate, and you copied it exactly with very insignificant changes. If the code is something anyone could have come up with, I would not cite a source.

For example, on the Matlab resource pages there are full codes a user can download and use, they have the authors name and the permissions usually commented at the top of the file. Also, if the code is related to a publication (such as Journal of Computer Vision) , it will usually cite the publication. Otherwise the code is on the web, free and open source.
Last edited on
Oh, alright. Thanks!
If you see something like this in the code that you pick up (this example is standard FreeBSD), you should honour the copyright and terms of use.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*-
* Copyright (c) 1988, 1993
* The Regents of the University of California.  All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in the
*    documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
*    may be used to endorse or promote products derived from this software
*    without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
Thanks for the example, JLBourges. I really do appreciate the help.
Topic archived. No new replies allowed.