forked from artofproblemsolving/pythonbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreface.html
More file actions
executable file
·274 lines (264 loc) · 17.2 KB
/
preface.html
File metadata and controls
executable file
·274 lines (264 loc) · 17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Preface — How to Think Like a Computer Scientist: Learning with Python 3 (AoPS Edition)</title>
<link rel="stylesheet" href="_static/style.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/codemirrorEdited.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '1.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="_static/pywindowCodemirrorC.js"></script>
<script type="text/javascript" src="_static/skulpt.min.js"></script>
<script type="text/javascript" src="_static/skulpt-stdlib.js"></script>
<script type="text/javascript" src="_static/aopsmods.js"></script>
<link rel="copyright" title="Copyright" href="copyright.html" />
<link rel="top" title="How to Think Like a Computer Scientist: Learning with Python 3 (AoPS Edition)" href="index.html" />
<link rel="next" title="Contributor List" href="contrib.html" />
<link rel="prev" title="Foreword" href="foreword.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="contrib.html" title="Contributor List"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="foreword.html" title="Foreword"
accesskey="P">previous</a> |</li>
<li><a href="index.html">How to Think Like a Computer Scientist: Learning with Python 3 (AoPS Edition)</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="body">
<div class="section" id="preface">
<h1>Preface<a class="headerlink" href="#preface" title="Permalink to this headline">¶</a></h1>
<p>By Jeffrey Elkner</p>
<p>This book owes its existence to the collaboration made possible by the Internet
and the free software movement. Its three authors—a college professor, a high
school teacher, and a professional programmer—never met face to face to work
on it, but we have been able to collaborate closely, aided by many other folks
who have taken the time and energy to send us their feedback.</p>
<p>We think this book is a testament to the benefits and future possibilities of
this kind of collaboration, the framework for which has been put in place by
Richard Stallman and the Free Software Foundation.</p>
<div class="section" id="how-and-why-i-came-to-use-python">
<h2>How and why I came to use Python<a class="headerlink" href="#how-and-why-i-came-to-use-python" title="Permalink to this headline">¶</a></h2>
<p>In 1999, the College Board’s Advanced Placement (AP) Computer Science exam was
given in C++ for the first time. As in many high schools throughout the
country, the decision to change languages had a direct impact on the computer
science curriculum at Yorktown High School in Arlington, Virginia, where I
teach. Up to this point, Pascal was the language of instruction in both our
first-year and AP courses. In keeping with past practice of giving students two
years of exposure to the same language, we made the decision to switch to C++
in the first year course for the 1997-98 school year so that we would be in
step with the College Board’s change for the AP course the following year.</p>
<p>Two years later, I was convinced that C++ was a poor choice to use for
introducing students to computer science. While it is certainly a very powerful
programming language, it is also an extremely difficult language to learn and
teach. I found myself constantly fighting with C++’s difficult syntax and
multiple ways of doing things, and I was losing many students unnecessarily as
a result. Convinced there had to be a better language choice for our first-year
class, I went looking for an alternative to C++.</p>
<p>I needed a language that would run on the machines in our GNU/Linux lab as well
as on the Windows and Macintosh platforms most students have at home. I wanted
it to be free software, so that students could use it at home regardless of
their income. I wanted a language that was used by professional programmers,
and one that had an active developer community around it. It had to support
both procedural and object-oriented programming. And most importantly, it had
to be easy to learn and teach. When I investigated the choices with these goals
in mind, Python stood out as the best candidate for the job.</p>
<p>I asked one of Yorktown’s talented students, Matt Ahrens, to give Python a try.
In two months he not only learned the language but wrote an application called
pyTicket that enabled our staff to report technology problems via the Web. I
knew that Matt could not have finished an application of that scale in so short
a time in C++, and this accomplishment, combined with Matt’s positive
assessment of Python, suggested that Python was the solution I was looking for.</p>
</div>
<div class="section" id="finding-a-textbook">
<h2>Finding a textbook<a class="headerlink" href="#finding-a-textbook" title="Permalink to this headline">¶</a></h2>
<p>Having decided to use Python in both of my introductory computer science
classes the following year, the most pressing problem was the lack of an
available textbook.</p>
<p>Free documents came to the rescue. Earlier in the year, Richard Stallman had
introduced me to Allen Downey. Both of us had written to Richard expressing an
interest in developing free educational materials. Allen had already written a
first-year computer science textbook, <em>How to Think Like a Computer Scientist</em>.
When I read this book, I knew immediately that I wanted to use it in my class.
It was the clearest and most helpful computer science text I had seen. It
emphasized the processes of thought involved in programming rather than the
features of a particular language. Reading it immediately made me a better
teacher.</p>
<p><em>How to Think Like a Computer Scientist</em> was not just an excellent book, but it
had been released under the GNU public license, which meant it could be used
freely and modified to meet the needs of its user. Once I decided to use
Python, it occurred to me that I could translate Allen’s original Java version
of the book into the new language. While I would not have been able to write a
textbook on my own, having Allen’s book to work from made it possible for me to
do so, at the same time demonstrating that the cooperative development model
used so well in software could also work for educational materials.</p>
<p>Working on this book for the last two years has been rewarding for both my
students and me, and my students played a big part in the process. Since I
could make instant changes whenever someone found a spelling error or difficult
passage, I encouraged them to look for mistakes in the book by giving them a
bonus point each time they made a suggestion that resulted in a change in the
text. This had the double benefit of encouraging them to read the text more
carefully and of getting the text thoroughly reviewed by its most important
critics, students using it to learn computer science.</p>
<p>For the second half of the book on object-oriented programming, I knew that
someone with more real programming experience than I had would be needed to do
it right. The book sat in an unfinished state for the better part of a year
until the open source community once again provided the needed means for its
completion.</p>
<p>I received an email from Chris Meyers expressing interest in the book. Chris
is a professional programmer who started teaching a programming course last
year using Python at Lane Community College in Eugene, Oregon. The prospect of
teaching the course had led Chris to the book, and he started helping out with
it immediately. By the end of the school year he had created a companion
project on our Website at <a class="reference external" href="http://openbookproject.net">http://openbookproject.net</a> called <a class="reference external" href="http://openbookproject.net/py4fun">*Python for Fun*</a> and was
working with some of my most advanced students as a master teacher, guiding
them beyond where I could take them.</p>
</div>
<div class="section" id="introducing-programming-with-python">
<h2>Introducing programming with Python<a class="headerlink" href="#introducing-programming-with-python" title="Permalink to this headline">¶</a></h2>
<p>The process of translating and using <em>How to Think Like a Computer Scientist</em>
for the past two years has confirmed Python’s suitability for teaching
beginning students. Python greatly simplifies programming examples and makes
important programming ideas easier to teach.</p>
<p>The first example from the text illustrates this point. It is the traditional
hello, world program, which in the Java version of the book looks like this:</p>
<blockquote>
<div><div class="highlight-java"><div class="highlight"><pre><span class="kd">class</span> <span class="nc">Hello</span> <span class="o">{</span>
<span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span> <span class="o">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="o">)</span> <span class="o">{</span>
<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span> <span class="o">(</span><span class="s">"Hello, world."</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
</div></blockquote>
<p>in the Python version it becomes:</p>
<blockquote>
<div><div class="highlight-python3"><div class="highlight"><pre><span class="nb">print</span><span class="p">(</span><span class="s">"Hello, World!"</span><span class="p">)</span>
</pre></div>
</div>
</div></blockquote>
<p>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 Java version has always forced me to choose between two
unsatisfying options: either to explain the <cite>class Hello</cite>,
<cite>public static void main</cite>, <cite>String[] args</cite>, <cite>{</cite>, and <cite>}</cite>, 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.</p>
<p>Comparing the explanatory text of the program in each version of the book
further illustrates what this means to the beginning student. There are
seven paragraphs of explanation of Hello, world! in the Java version; in the
Python version, there are only a few sentences. More importantly, the missing
six paragraphs do not deal with the big ideas in computer programming but with
the minutia of Java 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.</p>
<p>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 Java a variable is a
name for a place that holds a value if it is a built-in type, and a reference
to an object if it is not. Explaining this distinction requires a discussion
of how the computer stores data. 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.</p>
<p>Another example of how Python aids in the teaching and learning of programming
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
distinction 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 <tt class="docutils literal"><span class="pre">def</span></tt>, so I simply tell my students, When you define a function,
begin with <tt class="docutils literal"><span class="pre">def</span></tt>, 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.</p>
<p>Using Python improved the effectiveness of our computer science program for all
students. I saw a higher general level of success and a lower level of
frustration than I experienced teaching with either C++ or Java. I moved faster
with better results. More students left the course with the ability to create
meaningful programs and with the positive attitude toward the experience of
programming that this engenders.</p>
</div>
<div class="section" id="building-a-community">
<h2>Building a community<a class="headerlink" href="#building-a-community" title="Permalink to this headline">¶</a></h2>
<p>I have received email from all over the globe from people using this book to
learn or to teach programming. A user community has begun to emerge, and many
people have been contributing to the project by sending in materials for the
companion Website at <a class="reference external" href="http://openbookproject.net/pybiblio">http://openbookproject.net/pybiblio</a>.</p>
<p>With the continued growth of Python, I expect the growth in the user community
to continue and accelerate. The emergence of this user community and the
possibility it suggests for similar collaboration among educators have been the
most exciting parts of working on this project for me. By working together, we
can increase the quality of materials available for our use and save valuable
time. I invite you to join our community and look forward to hearing from you.
Please write to me at <a class="reference external" href="mailto:jeff%40elkner.net">jeff<span>@</span>elkner<span>.</span>net</a>.</p>
<div class="line-block">
<div class="line">Jeffrey Elkner</div>
<div class="line">Governor’s Career and Technical Academy in Arlington</div>
<div class="line">Arlington, Virginia</div>
</div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="contrib.html" title="Contributor List"
>next</a> |</li>
<li class="right" >
<a href="foreword.html" title="Foreword"
>previous</a> |</li>
<li><a href="index.html">How to Think Like a Computer Scientist: Learning with Python 3 (AoPS Edition)</a> »</li>
</ul>
</div>
<div class="footer">
© <a href="copyright.html">Copyright</a> 2014, AoPS Incorporated, 2012, Peter Wentworth, Jeffrey Elkner, Allen B. Downey and Chris Meyers.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.1.
</div>
</body>
</html>