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.
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 do 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.
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:
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.
It then goes on to clarify the granted personal use license:
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.
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).
My questions:
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?
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)?
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.