How to Think Like a Computer Scientist - Learning with Python

Peter Kitson

ISBN : 0971677506

Order a printed copy of this book from Amazon.

Cover Design - How to Think Like a Computer Scientist - Learning with Python

For your free electronic copy of this book please verify the numbers below. 

(We need to do this to make sure you're a person and not a malicious script)



Sample Chapter From How to Think Like a Computer Scientist - Learning with Python
     Copyright © Allen Downey, Jeffrey Elkner, Chris Meyers

Introducing programming with Python

The process of translating and using How to Think Like a Computer Scientist
for the past two years has con¯rmed Python\'s suitability for teaching beginning
students. Python greatly simpli¯es programming examples and makes impor-
tant programming ideas easier to teach.

The first example from the text illustrates this point. It is the traditional \hello,
world" program, which in the C++ version of the book looks like this:

#include <iostream.h>
void main()
cout << "Hello, world." << endl;

in the Python version it becomes:

print "Hello, World!"

Even though this is a trivial example, the advantages of Python stand out.
Yorktown\'s Computer Science I course has no prerequisites, so many of the
students seeing this example are looking at their first program. Some of them
are undoubtedly a little nervous, having heard that computer programming is
difficult to learn. The C++ version has always forced me to choose between
two unsatisfying options: either to explain the #include, void main(), f, and
g statements and risk confusing or intimidating some of the students right at
the start, or to tell them, "Just don\'t worry about all of that stuff now; we will
talk about it later," and risk the same thing. The educational objectives at
this point in the course are to introduce students to the idea of a programming
statement and to get them to write their first program, thereby introducing
them to the programming environment. The Python program has exactly what
is needed to do these things, and nothing more.

Comparing the explanatory text of the program in each version of the book
further illustrates what this means to the beginning student. There are thirteen
paragraphs of explanation of "Hello, world!" in the C++ version; in the Python
version, there are only two. More importantly, the missing eleven paragraphs
do not deal with the "big ideas" in computer programming but with the minu-
tia of C++ syntax. I found this same thing happening throughout the book.
Whole paragraphs simply disappear from the Python version of the text because
Python\'s much clearer syntax renders them unnecessary.

Using a very high-level language like Python allows a teacher to postpone talking
about low-level details of the machine until students have the background that
they need to better make sense of the details. It thus creates the ability to put
"first things first" pedagogically. One of the best examples of this is the way in
which Python handles variables. In C++ a variable is a name for a place that
holds a thing. Variables have to be declared with types at least in part because
the size of the place to which they refer needs to be predetermined. Thus, the
idea of a variable is bound up with the hardware of the machine. The powerful
and fundamental concept of a variable is already difficult enough for beginning
students (in both computer science and algebra). Bytes and addresses do not
help the matter. In Python a variable is a name that refers to a thing. This
is a far more intuitive concept for beginning students and is much closer to the
meaning of "variable" that they learned in their math courses. I had much less
difficulty teaching variables this year than I did in the past, and I spent less
time helping students with problems using them.

Another example of how Python aids in the teaching and learning of program-
ming is in its syntax for functions. My students have always had a great deal
of difficulty understanding functions. The main problem centers around the
difference between a function definition and a function call, and the related dis-
tinction between a parameter and an argument. Python comes to the rescue
with syntax that is nothing short of beautiful. Function definitions begin with
the keyword def, so I simply tell my students, "When you define a function,
begin with def, followed by the name of the function that you are defining;
when you call a function, simply call (type) out its name." Parameters go
with definitions; arguments go with calls. There are no return types, parameter
types, or reference and value parameters to get in the way, so I am now able
to teach functions in less than half the time that it previously took me, with
better comprehension.

Using Python has improved the effectiveness of our computer science program
for all students. I see a higher general level of success and a lower level of
frustration than I experienced during the two years I taught C++. I move faster
with better results. More students leave the course with the ability to create
meaningful programs and with the positive attitude toward the experience of
programming that this engenders.