Green Tea Press
|
Prefacefrom How to Think Like a Computer Scientist: Java Version.``As we enjoy great Advantages from the Inventions of others, we should be glad of an Opportunity to serve others by any Invention of ours, and this we should do freely and generously.'' Why I wrote this bookThis is the fourth edition of a book I started writing in 1999, when I was teaching at Colby College. I had taught an introductory computer science class using the Java programming language, but I had not found a textbook I was happy with. For one thing, they were all too big! There was no way my students would read 800 pages of dense, technical material, even if I wanted them to. And I didn't want them to. Most of the material was too specific---details about Java and its libraries that would be obsolete by the end of the semester, and that obscured the material I really wanted to get to.The other problem I found was that the introduction to object oriented programming was too abrupt. Many students who were otherwise doing well just hit a wall when we got to objects, whether we did it at the beginning, middle or end. So I started writing. I wrote a chapter a day for 13 days, and on the 14th day I edited. Then I sent it to be photocopied and bound. When I handed it out on the first day of class, I told the students that they would be expected to read one chapter a week. In other words, they would read it seven times slower than I wrote it. The philosophy behind itHere are some of the ideas that made the book the way it is:
But minimalism has some disadvantages. There is not much here that is intrinsically fun. Most of my examples demonstrate the most basic use of a language feature, and many of the exercises involve string manipulation and mathematical ideas. I think some of them are fun, but many of the things that excite students about computer science, like graphics, sound and network applications, are given short shrift. The problem is that many of the more exciting features involve lots of details and not much concept. Pedagogically, that means a lot of effort for not much payoff. So there is a tradeoff between the material that students enjoy and the material that is most intellectually rich. I leave it to individual teachers to find the balance that is best for their classes. To help, the book includes appendices that cover graphics, keyboard input and file input. Object-oriented programmingSome books introduce objects immediately; others warm up with a more procedural style and develop object-oriented style more gradually. This book is probably the extreme of the ``objects late'' approach.Many of Java's object-oriented features are motivated by problems with previous languages, and their implementations are influenced by this history. Some of these features are hard to explain if students aren't familiar with the problems they solve. It wasn't my intention to postpone object-oriented programming. On the contrary, I got to it as quickly as I could, limited by my intention to introduce concepts one at a time, as clearly as possible, in a way that allows students to practice each idea in isolation before adding the next. It just happens that it takes 13 steps. Data structuresIn Fall 2000 I taught the second course in the introductory sequence, called Data Structures, and wrote additional chapters covering lists, stacks, queues, trees, and hashtables.Each chapter presents the interface for a data structure, one or more algorithms that use it, and at least one implementation. In most cases there is also an implementation in the java.utils package, so teachers can decide on a case-by-case basis whether to discuss the implementation, and whether students will build an implementation as an exercise. For the most part I present data structures and interfaces that are consistent with the implementation in java.utils. The Computer Science AP ExamDuring Summer 2001 I worked with teachers at the Maine School of Science and Mathematics on a version of the book that would help students prepare for the Computer Science Advanced Placement Exam, which used C++ at the time. The translation went quickly because, as it turned out, the material I covered was almost identical to the AP Syllabus.Naturally, when the College Board announced that the AP Exam would switch to Java, I made plans to update the Java version of the book. Looking at the proposed AP Syllabus, I saw that their subset of Java was all but identical to the subset I had chosen. During January 2003, I worked on the Fourth Edition of the book, making these changes:
Free books!Since the beginning, this book and its descendents have been available under the GNU Free Documentation License. Readers are free to download the book in a variety of formats and print it or read it on screen. Teachers are free to send the book to a short-run printer and make as many copies as they need. And, maybe most importantly, anyone is free to customize the book for their needs. You can download the LaTeX source code, and then add, remove, edit, or rearrange material, and make the book that is best for you or your class.People have translated the book into other computer languages (including Python and Eiffel), and other natural languages (including Spanish, French and German). Many of these derivatives are also available under the GNU FDL. This approach to publishing has a lot of advantages, but there is one drawback: my books have never been through a formal editing and proofreading process and, too often, it shows. Motivated by Open Source Software, I have adopted the philosophy of releasing the book early and updating it often. I do my best to minimize the number of errors, but I also depend on readers to help out. The response has been great. I get messages almost every day from people who have read the book and liked it enough to take the trouble to send in a ``bug report.'' Often I can correct an error and post an updated version almost immediately. I think of the book as a work in progress, improving a little whenever I have time to make a revision, or when readers take the time to send feedback. Oh, the titleI get a lot of grief about the title of the book. Not everyone understands that it is---mostly---a joke. Reading this book will probably not make you think like a computer scientist. That takes time, experience, and probably a few more classes.But there is a kernel of truth in the title: this book is not about Java, and it is only partly about programming. If it is successful, this book is about a way of thinking. Computer scientists have an approach to problem-solving, and a way of crafting solutions, that is unique, versatile and powerful. I hope that this book gives you a sense of what that approach is, and that at some point you will find yourself thinking like a computer scientist.
Allen B. Downey |