Skip to content

Commit 6521b67

Browse files
authored
Merge pull request #2 from object-oriented-python/vimeo
Book
2 parents 5f0bafc + 3466aa0 commit 6521b67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+58466
-2617
lines changed

doc/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ latexpdf: apidoc
138138
cd $(BUILDDIR)/latex; latexmk -pdf
139139
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
140140

141+
book:
142+
$(SPHINXBUILD) $(ALLSPHINXOPTS) -b latex -t book $(BUILDDIR)/book
143+
@echo
144+
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/book."
145+
@echo "Run \`make' in that directory to run these through (pdf)latex" \
146+
"(use \`make bookpdf' here to do that automatically)."
147+
148+
bookpdf:
149+
PYTHONPATH=$(PWD)/..:$(PYTHONPATH) $(SPHINXBUILD) -b latex -t book $(ALLSPHINXOPTS) $(BUILDDIR)/book
150+
@echo "Running LaTeX files through pdflatex..."
151+
# $(MAKE) -C $(BUILDDIR)/latex all-pdf
152+
cd $(BUILDDIR)/book; latexmk -pdf
153+
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/book."
154+
141155
latexpdfja: apidoc
142156
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
143157
@echo "Running LaTeX files through platex and dvipdfmx..."

doc/source/0_preface.rst

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
Preface
2+
=======
3+
4+
Computers have revolutionised mathematics and the many scientific, engineering
5+
and economic fields in which mathematics is applied. In the applications of
6+
mathematics the role of computation has long been obvious and prominent. Now,
7+
the development of theorem proving software is increasing the prominence of
8+
computing in pure mathematics. What this means is that the ability to write
9+
computer programs well is an indispensable part of the toolkit of a 21st
10+
century mathematician and, indeed, scientist or engineer.
11+
12+
Regrettably, university courses in mathematics and its sibling disciplines have
13+
often failed to reflect this revolution in the way that mathematics is
14+
practised. Far too often the sum total of programming education in an
15+
undergraduate degree is a computational methods module in which students are
16+
shown elementary programming constructs such as functions, loops, and perhaps
17+
plotting. These are introduced in the context of solving particular
18+
computational mathematics or statistics problems, and the programming
19+
constructs introduced are driven by what is needed to solve those problems.
20+
21+
The assumptions underpinning this approach seem to be some combination of a
22+
belief that maths degrees should only teach maths, as well a feeling that the
23+
mathematical algorithms are some how the difficult part and that programming is
24+
a mere technical skill that students will somehow pick up along the way. The
25+
consequence of this approach is that many maths students and graduates end up
26+
without the programming, software development, and debugging skills that they
27+
need to make effective use of computers in their further studies or working
28+
careers.
29+
30+
What is this book for?
31+
----------------------
32+
33+
This book is the result of a significant change in the mathematics curriculum
34+
at Imperial College London. Rather than assume that students will somehow
35+
acquire programming skills along the way, we have introduced first and second
36+
year courses with the sole objective of teaching students to programme well.
37+
This book is the text for the second of these courses. Named "Principles of
38+
Programming", the course aims to take students with a knowledge of basic Python
39+
programming (functions, loops, plotting and so forth) and introduce them to
40+
higher level programming concepts.
41+
42+
The objective of this course is to graduate better programmers. Material on
43+
new programming constructs and concepts is accompanied by chapters on good
44+
programming style, so that students learn how to write code that they and
45+
others can understand, and on errors, exceptions and debugging, so that
46+
students learn how to get themselves out of trouble.
47+
48+
An underlying theme throughout this book is that programming has strong
49+
connections with mathematics. In particular, both mathematics and programming
50+
depend on building higher level, more abstract objects which encapsulate and
51+
hide the underlying complexity of operations. It is in taking this mathematical
52+
approach to programming that this book is "for mathematicians".
53+
54+
The examples are chosen from across mathematics. For example, it appears to be
55+
traditional in object oriented programming books to use a telephone directory
56+
as the initial example of classes. We eschew this in favour of a class
57+
implementing polynomials. This provides the opportunity to introduce
58+
encapsulation and operator overloading for a familiar mathematical object. In
59+
contrast to the traditional computational methods courses, the examples are
60+
chosen to illustrate and explain the programming concepts we study rather than
61+
the converse.
62+
63+
Who is this book for?
64+
---------------------
65+
66+
This book is for anyone with mathematical, scientific, or engineering interests
67+
who would like to learn to be a more capable programmer. The mathematical
68+
examples assume that you know how to differentiate functions of one variable,
69+
but very little beyond that. Where examples or exercises employ other
70+
mathematics, such as cellular automata in :numref:`Chapter %s <style>` and
71+
groups in :numref:`Chapter %s <abstract_data_types>`, enough of the mathematics
72+
will be introduced that the reader should be able to understand the programming
73+
concept being explained, without necessarily understanding all of the
74+
mathematical details of the example.
75+
76+
This is not an introduction to basic Python: it's assumed that the reader knows
77+
the sort of basic Python usually covered in a first programming or
78+
computational methods course. In particular the reader will be assumed to be
79+
familiar with writing functions, variable assignments, loops, and list
80+
comprehensions. The reader is also assumed to have used numeric and string data
81+
values, as well as dictionaries, lists, and tuples.
82+
83+
Many introductory Python courses exclusively use Jupyter notebooks, so nothing
84+
beyond that is assumed. Getting set up with a working Python installation is
85+
covered in :numref:`Chapter %s <introduction>` while the Python command line
86+
and using a text editor to create programmes in files are introduced from
87+
scratch in :numref:`Chapter %s <programs_files>`.
88+
89+
How to use this book
90+
--------------------
91+
92+
.. only:: latex
93+
94+
You can, of course, simply sit down and read this book from cover to cover,
95+
or dip in to see what it has to say on particular subjects. However,
96+
reading a book about programming will not teach you to program. For that,
97+
you need to get your hands dirty writing code and debugging your mistakes.
98+
To help with this there is a book website at:
99+
100+
`https://object-oriented-programming.github.io
101+
<https://object-oriented-programming.github.io>`__
102+
103+
As well as a web version of the full text of the book, the website contains
104+
videos and the code needed to do the programming exercises at the end of
105+
each chapter.
106+
107+
.. only:: html
108+
109+
You can, of course, simply sit down and read this book from cover to cover,
110+
or dip in to see what it has to say on particular subjects. However,
111+
reading a book about programming will not teach you to program. For that,
112+
you need to get your hands dirty writing code and debugging your mistakes.
113+
The videos and exercises throughout the book are designed to help you do
114+
this.
115+
116+
The videos
117+
..........
118+
119+
The videos were created to accompany the course at Imperial College London.
120+
They're not primarily lecture videos but are instead practical demonstrations
121+
of the programming concepts being introduced at the relevant point. Usually
122+
it's better to watch the video *after* reading the relevant section.
123+
124+
.. only:: latex
125+
126+
The videos are marked in the text by a blue box at the right hand side,
127+
containing the video number. This corresponds to the list of links at:
128+
129+
`https://object-oriented-programming.github.io/edition1/videos.html
130+
<https://object-oriented-programming.github.io/edition1/videos.html>`__
131+
132+
The exercises
133+
.............
134+
135+
At the end of each chapter are exercises. These usually depend on a skeleton
136+
code which is available on GitHub. Sometimes you might be asked to complete a
137+
piece of code while on other occasions you'll need to write a whole Python
138+
module from scratch. Each set of exercises will come with a matching set of
139+
tests. These are small programs which check whether your code produces the
140+
correct responses to a range of inputs. Tests like this provide immediate
141+
feedback and enable you to know how you are doing. Links to the skeleton code
142+
for each chapter are provided at:
143+
144+
`https://object-oriented-programming.github.io/edition1/exercises.html
145+
<https://object-oriented-programming.github.io/edition1/exercises.html>`__
146+
147+
148+
Conventions employed
149+
--------------------
150+
151+
Each chapter starts by introducing new material, supported by the videos and
152+
exercises. At the end of each chapter is a glossary containing many of the key
153+
concepts introduced in that chapter. Terms to be found in a glossary are given
154+
*in italics* and can be looked up in the index.
155+
156+
.. only:: not book
157+
158+
Python has excellent `official online documentation
159+
<https://docs.python.org/3/>`_, and we link to that throughout the text.
160+
External links show up in purple while :ref:`internal links to other parts
161+
of the notes <introduction>` are blue.
162+
163+
The text sometimes introduces counterexamples: illustrations of code errors or
164+
bad implementation ideas. These will be flagged with a big red cross:
165+
166+
.. container:: badcode
167+
168+
.. code-block:: python3
169+
170+
print "Hello World"
171+
172+
Conversely, if it's necessary in context to highlight which approach is the
173+
correct one, the code will come with a big green tick:
174+
175+
.. container:: goodcode
176+
177+
.. code-block:: python3
178+
179+
print("Hello World")
180+
181+
182+
Teaching this course elsewhere
183+
------------------------------
184+
185+
The course of which this book forms the text has been given to master's
186+
students at the University of Oxford, as well as to undergraduate students at
187+
Imperial College London. Instructors are welcome to use this material to teach
188+
elsewhere, and are encouraged to contact the author for assistance with access
189+
to materials.
190+
191+
Acknowledgements
192+
----------------
193+
194+
The course Principles of Programming, and the notes on which this book is
195+
based, were first delivered in spring 2020, when university teaching was
196+
completely online during the COVID pandemic. I'd like to thank teaching fellow
197+
Dr Matthew Woolway who worked tirelessly with me on the module and who put
198+
together many of the tests on the exercises, and the graduate teaching
199+
assistants Miguel Boland, Sophia Vorderwuelbecke and Connor Ward whose
200+
professionalism in delivering the course in very complex circumstances was
201+
outstanding. Pulling out all the stops to deliver the written and video
202+
materials for online learning meant a lot of evenings and weekends. I am
203+
exceptionally grateful to my wife Gebina Ham for disproportionately picking up
204+
our childcare responsibilities in that period in order to make this possible.
205+
206+
This is a textbook about programming in Python, so it would be remiss of me not
207+
to also thank the developers of the Python language, its CPython reference
208+
implementation, and all the third party packages which on which this book
209+
depends. In that regard, the developers of Numpy, Flake8, Pytest, PDB++ and
210+
IPython deserve particular mention.
211+
212+
This book is typeset using the Sphinx documentation system. Among other things
213+
this facilitates generating the web, PDF, and print versions of the book from a
214+
single source. Thanks are due to its authors as well as those of the underlying
215+
LaTeX and TeX typesetting systems.

0 commit comments

Comments
 (0)