A first course in computer science is about a new way of solving problems: computationally. As a result, the focus of a first course in computation should be on problem solving. However, practically speaking the teaching of problem solving is inexorably intertwined with the computer language used. Thus, the choice of language for this first course is very important.
We have chosen Python as a the introductory language for beginning programming students, majors and non-majors alike, based on our combined thirty years of experience teaching undergraduateintroductory computer science at Michigan State University. Having taught the course in Pascal, C/C++ and now Python, we know that an introductory programming language should have two characteristics. First, it should be relatively simple to learn. A first course in programming is mostly about problem solving and learning to be more rigorous in applying problem solving to new problems. The programming language should get in the way as little as possible. Python’s simplicity, powerful built-in data structures and advanced control constructs allow students to focus more on problem solving and less on language issues. Second, it should practical. The students should see that they might use what they are learning while they are learning it. Python supports learning fundamental programming issues such as typical programming constructs, a fundamental object oriented approach, common data structures etc. but also more complex computing issues such as threads, regular expressions, as well as practical problems such as web access, database manipulation and thousands of others from nearly any discipline imaginable. For having taken one course in programming, a student, any student (major or not), should walk away from a CS1 course and somewhere later in their career address a problem by thinking; “Hey, I’ll just write a program to solve that.” For us, that is computational thinking and we have seen examples of this, typically in students coming back to us from earlier semesters thanking us for what they learned, every semester since the move to Python.
We emphasize both the fundamental issues of programming and practicality by focusing on data manipulation and analysis as a theme—allowing students to work on real problems using either publically available datasets from various Internet sources or self generated data sets from their own work and interests. We also emphasize the development of programs, providing three chapters for detailed design and implementation of programs. As part of this one semester course our students have analyzed breast cancer data, catalogued movie actor relationships, predicted disruptions of satellites from solar storms and other data analysis kinds of problem. We have also found that concepts learned in a Python CS1 course transitioned to a CS2 C++ course with little or no impact on either the class material or the students (see our SIGCSE 2009 paper).
Our goals for the book are as follows:
At the highest level our text follows a fairly traditional CS1 order though there are some differences. For example, we cover strings rather early (before functions) so that we can do more data manipulation early on. We also include elementary file I/O early for the same reason, leaving detailed coverage for a later chapter. Given our theme of data manipulation, we feel this is appropriate. We also “sprinkle” topics like plotting and drawing throughout the text in service of the data manipulation theme.
We use an “object-use-first” approach where we use objects and their methods early in the book while leaving the design and implementation of user-designed objects for later—after mastery of the use of objects. We have found the students are more receptive to building their own classes once they have experienced the usefulness of existing objects. In other words we motivate the need for writing classes.Functions are split into two parts because of how Python handles mutable objects such as lists as parameters—discussion of those issues can only come after there is an understanding of lists as mutable objects.
Three of the chapters (3, 10, 13) are primarily program design chapters, providing an opportunity to “tie things together” as well as showing how to design a solution. We try to get students using the data structures as early as possible. Strings, lists, and dictionaries are covered as early as possible.
A few chapters are intended as supplemental reading material for the students though lecturers may choose to cover these topics as well. For background we provide a Chapter 0 that introduces some general concepts of a computer as a device and some computer terminology. We feel such an introduction is important because everyone should understand a little about a computer, but this material can be left for reading. The last chapters in the text may not be reached in some courses.
We have tried to focus on non-numeric examples into the book, but some numeric examples are classics for a good reason. For example, we use a Rational numbers example for creating classes that overload operators. Our goal was always to use the best examples.
Throughout the text we emphasize problem solving, especially the useful divide-and-conquer approach to developing a solution. Three chapters (3, 10 and 13) are devoted almost exclusively to program development. Here we walk students through the solution of larger examples. In addition to design, we show mistakes and how to recover from them. That is, we don’t simply show a solution, but show a process of developing a solution.
We are particularly appreciative of the reviewers who provided valuable feedback at multiple stages of this endeavor: Claude Anderson (Rose-Hulman), Chris Brooks (University of San Francisco), Judy Franklin (Smith College), Alan Garvey (Truman State University), Ronald I. Greenberg (Loyola University), Andrew Harrington (Loyola College), Steve Harrison (Virginia Tech), Christopher Haynes (Indiana University), Cinda Heeren (University of Illinois - Urbana-Champaign), Brian Howard (DePauw University) Janardhan Iyengar (Franklin & Marshall College), Andree Jacobson (University of New Mexico), John Lasseter (Willamette University), Jim Mahoney (Marlboro College), Joe Oldham (Centre College), Holly Patterson-McNeill (Lewis Clark State College), John Rabung (Randolph-Macon College), Ben Schafer (University of Northern Iowa), David G. Sullivan (Boston University), David A. Sykes (Wofford Colllege). Here at MSU Erik Eid (now of Bowling Green) provided valuable feedback on the first draft. Laurie Dillon provided feedback when she taught from a draft. C. Titus Brown read a draft from a Pythonic perspective, and provided encouragement. As a high-school student Angus Burton provided valuable feedback from a novice¿s perspective. Srikanth Vudayagiri provided many excellent exercises. Scott Buffa made corrections to an early draft. The summer CSE 231 class provided many exercises: Mohammed Alwahibi, Younsuk Dong, Michael Ford, Gabriel Friedman, Adam Hamilton, Meagan Houang, Ruba Jiddou, and Adam Palmer. The organization of our course was established by Mark McCullen who is always available for advice. Larry Nyhoff (Calvin College) shared valuable insights over a dinner that started it all.