Personal copying of source code from a programming book
<p>Many books on computer programming publish source code listings and example programs as part of the printed book to demonstrate some aspect of the language. When I'm learning from such books, I typically copy one or more examples from the book into my computer in order to run them, study them, run them using a debugger, etc. I copy the version from the printed book and do not use any other included media such as CD-ROMs or Web sites. I had always assumed this sort of copying for personal use on my own computer would not be considered copyright infringement, but now I'm not so sure.</p>

<p>Sometimes, the book does mention an implied license near the beginning that clarifies how the source code can be used. In this case, the license normally allows copying for the sort of purpose I'm talking about. But in the large majority of cases, there is no license mentioned at all pertaining to how the source code included in the book may be used. If there are electronic media provided with the book (CD-ROM, Web site, etc.), the electronic versions of the source code typically <em>do</em> mention a license, but I do not typically make use of such media, so for the purpose of this question I want to ignore them.</p>

<p>In one unusual example, there is a well-known programming book that explicitly forbids any personal use of the source code in the book on a computer without first obtaining a license:</p>

<blockquote>
  <p>You must read this section if you intend to use the code in this book
  on a computer [...]. Without the license [...] this book is intended
  as a text and reference book, for reading and study purposes only.</p>
</blockquote>

<p>It then goes on to clarify the granted personal use license:</p>

<blockquote>
  <p>If you personally keyboard no more than 10 routines from this book
  into your computer, then we authorize you (and only you) to use those
  routines (and only those routines) on that single computer.</p>
</blockquote>

<p>However, I cannot accept this license due to the restrictions. For example, I may want to keyboard more than 10 routines. And I may want to use some method of copying other than to "personally keyboard" them (e.g. automatic dictation software).</p>

<p>My questions:</p>

<ol>
<li><p>For the case that a book does not include a license that mentions copying the source code from the book version, is it allowed for the reader to make personal copies of the source code to run on one's own computer?</p></li>
<li><p>For the case that a book does include a license, but that license is found to be unacceptable by the reader, is it allowed for the reader to make the personal copies? Does the fact that there is a license offer that the reader does not agree to make any legal difference as compared with case 1 (no license offered at all)?</p></li>
</ol>

<p>Assume that the source code to be copied would normally qualify for copyright protection (i.e. do not consider trivial source code examples that by themselves may not be eligible for copyright), and that the reader either owns or is borrowing (e.g. from a lending library) a legal copy of the book.</p>

<p><a href="/questions/tagged/united-states" class="post-tag" title="show questions tagged &#39;united-states&#39;" rel="tag">united-states</a></p>
<p>Ignoring fair use, copying code in which copyright subsists would be copyright infringement.</p>
<blockquote>
<p>... the owner of copyright under this title has the exclusive rights [...] to reproduce the copyrighted work (<a href="https://www.law.cornell.edu/uscode/text/17/106" rel="nofollow noreferrer">17 USC 106</a>)</p>
</blockquote>
<p>Code is eligible for copyright as a literary work.</p>
<blockquote>
<p>Copyright protection subsists [...] in original works of authorship fixed in any tangible medium of expression [...] Works of authorship include [...] literary works [...] (<a href="https://www.law.cornell.edu/uscode/text/17/102" rel="nofollow noreferrer">17 USC 102</a>)</p>
</blockquote>
<p><a href="http://www.cafc.uscourts.gov/sites/default/files/opinions-orders/13-1021.Opinion.5-7-2014.1.PDF" rel="nofollow noreferrer">Oracle v Google. (Fed. Cir. 2014)</a>:</p>
<blockquote>
<p>It is undisputed that computer programs—
defined in the Copyright Act as a set of statements or
instructions to be used directly or indirectly in a computer
in order to bring about a certain result, 17 U.S.C.
§ 101—can be subject to copyright protection as literary
works.</p>
</blockquote>
<p>One way that copying the code would <em>not</em> be infringement is under a <a href="https://law.stackexchange.com/questions/9526/do-i-need-permission-to-reimplement-application-programming-interface-calls-clas/9606#9606">scenes a faire or merger analysis</a>. In some circuits (e.g. 6th Circuit), scenes a faire/merger can preclude copyrightability. In other circuits (e.g. 2nd and 9th Circuits), these apply as affirmative defences <em>after</em> an initial finding of infringement. In either case, just as in fair use, this would be a case-by-case analysis, so we can't provide a blanket answer.</p>

<p>The <em>scenes-a-faire</em> (required scenes, or literally &quot;scenes to be made&quot;) doctrine recognizes that some aspects of a copyrighted work in some genre may be traits of the genre, and thus not copyrightable in and of themselves.  Further, the merger doctrine says that if there only a very limited number of ways of expressing something, none are copyrightable in and of themselves.  Many code examples in programming books, chip vendor data sheets, etc. are intended to show the essence of what would be expected in a generic application that performs a particular task.  For example, a typical UART transmit routine would look something like:</p>
<pre><code>void put_char(unsigned ch)
{
  while(!(UART0-&gt;TXSTAT &amp; UART_TXSTAT_READY_MASK))
    ;
  UART0-&gt;TXDATA = ch;
}
</code></pre>
<p>using identifier names that match those given in the device manufacturer's data sheet or technical reference manual.  While there might potentially be a small amount of creativity in the choice of whether to use the ! operator or compare the result of the bit mask with zero, how to format the dummy statement in the loop, etc. there are only a small number of ways of expressing something like the above without being gratuitously unclear.</p>
<p>In a sense, many programming examples in books are designed to show how a construct might be implemented in code <em>if the programmer makes no attempt to be original</em>.  If an example intended to avoid being particularly &quot;original&quot;, that would imply that the author was not trying to satisfy the copyright laws' rule that only original works can be copyrighted.</p>
<p>The fact that individual code snippets aren't copyrightable doesn't mean another author could simply copy all of them.  If an author is seeking to make a number of programming examples fit together well for pedagogical purposes, minor differences that would be irrelevant when code is fed to the machine may make it easier or harder for readers to understand what is going on, and as a consequence the design of code snippets designed for teaching may require more originality and creativity than the design of snippets that are intended to direct machines to accomplish useful tasks.</p>

copyright fair-use