-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path0_preface.html
More file actions
256 lines (243 loc) · 16.7 KB
/
0_preface.html
File metadata and controls
256 lines (243 loc) · 16.7 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
<!DOCTYPE html>
<html lang="en" data-content_root="./">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Preface — Object-oriented Programming documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/fenics.css?v=8c7d05f9" />
<link rel="stylesheet" type="text/css" href="_static/proof.css" />
<link rel="stylesheet" type="text/css" href="_static/graphviz.css?v=fd3f3429" />
<script src="_static/documentation_options.js?v=5929fcd5"></script>
<script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/proof.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="1. Introduction: abstraction in mathematics and programming" href="1_introduction.html" />
<link rel="prev" title="Object oriented programming in Python for mathematicians" href="index.html" />
<!--[if lte IE 6]>
<link rel="stylesheet" href="_static/ie6.css" type="text/css" media="screen" charset="utf-8" />
<![endif]-->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-0EFVH5C4DC"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-0EFVH5C4DC');
</script>
<link rel="stylesheet" href="_static/featured.css">
<link rel="shortcut icon" href="_static/icon.ico" />
</head><body>
<div class="wrapper">
<a href="index.html"><img src="_static/banner.png" width="900px" alt="FInAT Project Banner" /></a>
<div id="access">
<div class="menu">
<ul>
<li class="page_item"><a href="index.html" title="Book">Book</a></li>
<li class="page_item"><a href="videos.html" title="Videos">Videos</a></li>
<li class="page_item"><a href="exercises.html"
title="Exercises">Exercises</a></li>
<li class="page_item"><a href="installation.html" title="Installation">Installation</a></li>
</ul>
</div><!-- .menu -->
</div><!-- #access -->
</div><!-- #wrapper -->
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="preface">
<h1>Preface<a class="headerlink" href="#preface" title="Link to this heading">¶</a></h1>
<p>Computers have revolutionised mathematics and the many scientific, engineering,
and economic fields in which mathematics is applied. In the applications of
mathematics the role of computation has long been obvious and prominent. Now,
the development of theorem proving software is increasing the prominence of
computing in pure mathematics. What this means is that the ability to write
computer programs well is an indispensable part of the toolkit of a 21st
century mathematician and, indeed, scientist or engineer.</p>
<p>Regrettably, university courses in mathematics and its sibling disciplines have
often failed to reflect this revolution in the way that mathematics is
practised. Far too often the sum total of programming education in an
undergraduate degree is a computational methods module in which students are
shown elementary programming constructs such as functions, loops, and perhaps
plotting. These are introduced in the context of solving particular
computational mathematics or statistics problems, and the programming
constructs introduced are driven by what is needed to solve those problems.</p>
<p>The assumptions underpinning this approach seem to be some combination of a
belief that maths degrees should only teach maths, as well a feeling that the
mathematical algorithms are some how the difficult part and that programming is
a mere technical skill that students will somehow pick up along the way. The
consequence of this approach is that many maths students and graduates end up
without the programming, software development, and debugging skills that they
need to make effective use of computers in their further studies or working
careers.</p>
<section id="what-is-this-book-for">
<h2>What is this book for?<a class="headerlink" href="#what-is-this-book-for" title="Link to this heading">¶</a></h2>
<p>This book is the result of a significant change in the mathematics curriculum
at Imperial College London. Rather than assume that students will somehow
acquire programming skills along the way, we have introduced first and second
year courses with the sole objective of teaching students to programme well.
This book is the text for the second of these courses. Named “Principles of
Programming”, the course aims to take students with a knowledge of basic Python
programming (functions, loops, plotting and so forth) and introduce them to
higher level programming concepts.</p>
<p>The objective of this course is to graduate better programmers. Material on
new programming constructs and concepts is accompanied by chapters on good
programming style, so that students learn how to write code that they and
others can understand, and on errors, exceptions and debugging, so that
students learn how to get themselves out of trouble.</p>
<p>An underlying theme throughout this book is that programming has strong
connections with mathematics. In particular, both mathematics and programming
depend on building higher level, more abstract objects which encapsulate and
hide the underlying complexity of operations. It is in taking this mathematical
approach to programming that this book is “for mathematicians”.</p>
<p>The examples are chosen from across mathematics. For example, it appears to be
traditional in object oriented programming books to use a telephone directory
as the initial example of classes. We eschew this in favour of a class
implementing polynomials. This provides the opportunity to introduce
encapsulation and operator overloading for a familiar mathematical object. In
contrast to the traditional computational methods courses, the examples are
chosen to illustrate and explain the programming concepts we study rather than
the converse.</p>
</section>
<section id="who-is-this-book-for">
<h2>Who is this book for?<a class="headerlink" href="#who-is-this-book-for" title="Link to this heading">¶</a></h2>
<p>This book is for anyone with mathematical, scientific, or engineering interests
who would like to learn to be a more capable programmer. The mathematical
examples assume that you know how to differentiate functions of one variable,
but very little beyond that. Where examples or exercises employ other
mathematics, such as cellular automata in <a class="reference internal" href="4_style.html#style"><span class="std std-numref">Chapter 4</span></a> and
groups in <a class="reference internal" href="7_inheritance.html#inheritance"><span class="std std-numref">Chapter 7</span></a>, enough of the mathematics
will be introduced that the reader should be able to understand the programming
concept being explained, without necessarily understanding all of the
mathematical details of the example.</p>
<p>This is not an introduction to basic Python: it’s assumed that the reader knows
the sort of basic Python usually covered in a first programming or
computational methods course. In particular the reader will be assumed to be
familiar with writing functions, variable assignments, loops, and list
comprehensions. The reader is also assumed to have used numeric and string data
values, as well as dictionaries, sets, lists, and tuples.</p>
<p>Many introductory Python courses exclusively use Jupyter notebooks, so nothing
beyond that is assumed. Getting set up with a working Python installation is
covered in <a class="reference internal" href="1_introduction.html#introduction"><span class="std std-numref">Chapter 1</span></a> while the Python command line
and using a text editor to create programmes in files are introduced from
scratch in <a class="reference internal" href="2_programs_in_files.html#programs-files"><span class="std std-numref">Chapter 2</span></a>.</p>
</section>
<section id="how-to-use-this-book">
<h2>How to use this book<a class="headerlink" href="#how-to-use-this-book" title="Link to this heading">¶</a></h2>
<p>You can, of course, simply sit down and read this book from cover to cover,
or dip in to see what it has to say on particular subjects. However,
reading a book about programming will not teach you to program. For that,
you need to get your hands dirty writing code and debugging your mistakes.
The videos and exercises throughout the book are designed to help you do
this.</p>
<section id="the-videos">
<h3>The videos<a class="headerlink" href="#the-videos" title="Link to this heading">¶</a></h3>
<p>The videos were created to accompany the course at Imperial College London.
They’re not primarily lecture videos but are instead practical demonstrations
of the programming concepts being introduced at the relevant point. Usually
it’s better to watch the video <em>after</em> reading the relevant section.</p>
</section>
<section id="the-exercises">
<h3>The exercises<a class="headerlink" href="#the-exercises" title="Link to this heading">¶</a></h3>
<p>At the end of each chapter are exercises. These usually depend on a skeleton
code which is available on GitHub. Sometimes you might be asked to complete a
piece of code while on other occasions you’ll need to write a whole Python
module from scratch. Each set of exercises will come with a matching set of
tests. These are small programs which check whether your code produces the
correct responses to a range of inputs. Tests like this provide immediate
feedback and enable you to know how you are doing. Links to the skeleton code
for each chapter are provided at:</p>
<blockquote>
<div><p><a class="reference external" href="https://object-oriented-python.github.io/edition3/exercises.html">https://object-oriented-python.github.io/edition3/exercises.html</a></p>
</div></blockquote>
</section>
</section>
<section id="conventions-employed">
<h2>Conventions employed<a class="headerlink" href="#conventions-employed" title="Link to this heading">¶</a></h2>
<p>Each chapter starts by introducing new material, supported by the videos and
exercises. At the end of each chapter is a glossary containing many of the key
concepts introduced in that chapter. Terms to be found in a glossary are given
<em>in italics</em> and can be looked up in the index.</p>
<p>Python has excellent <a class="reference external" href="https://docs.python.org/3/">official online documentation</a>, and we link to that throughout the text.
External links show up in purple while <a class="reference internal" href="1_introduction.html#introduction"><span class="std std-ref">internal links to other parts
of the notes</span></a> are blue.</p>
<p>The text sometimes introduces counterexamples: illustrations of code errors or
bad implementation ideas. These will be flagged with a big red cross:</p>
<div class="badcode docutils container">
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nb">print</span> <span class="s2">"Hello World"</span>
</pre></div>
</div>
</div>
<p>Conversely, if it’s necessary in context to highlight which approach is the
correct one, the code will come with a big green tick:</p>
<div class="goodcode docutils container">
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="s2">"Hello World"</span><span class="p">)</span>
</pre></div>
</div>
</div>
</section>
<section id="teaching-this-course-elsewhere">
<h2>Teaching this course elsewhere<a class="headerlink" href="#teaching-this-course-elsewhere" title="Link to this heading">¶</a></h2>
<p>The course of which this book forms the text has been given to master’s
students at the University of Oxford, as well as to undergraduate students at
Imperial College London. Instructors are welcome to use this material to teach
elsewhere, and are encouraged to contact the author for assistance with access
to materials.</p>
</section>
<section id="acknowledgements">
<h2>Acknowledgements<a class="headerlink" href="#acknowledgements" title="Link to this heading">¶</a></h2>
<p>The course Principles of Programming, and the notes on which this book is
based, were first delivered in spring 2020, when university teaching was
completely online during the COVID pandemic. I’d like to thank teaching fellow
Dr Matthew Woolway who worked tirelessly with me on the module and who put
together many of the tests on the exercises, and the graduate teaching
assistants Miguel Boland, Sophia Vorderwuelbecke, and Connor Ward whose
professionalism in delivering the course in very complex circumstances was
outstanding. Pulling out all the stops to deliver the written and video
materials for online learning meant a lot of evenings and weekends. I am
exceptionally grateful to my wife Gebina Ham for disproportionately picking up
our childcare responsibilities in that period in order to make this possible.
I’d also like to thank Dr Aaron Pereira and Reuben Nixon-Hill for their
eagle-eyed corrections to the text.</p>
<p>This is a textbook about programming in Python, so it would be remiss of me not
to also thank the developers of the Python language, its CPython reference
implementation, and all the third party packages which on which this book
depends. In that regard, the developers of Numpy, Flake8, Pytest, PDB++ and
IPython deserve particular mention.</p>
<p>This book is typeset using the Sphinx documentation system. Among other things
this facilitates generating the web, PDF, and print versions of the book from a
single source. Thanks are due to its authors as well as those of the underlying
LaTeX and TeX typesetting systems.</p>
</section>
<section id="changes-in-the-second-and-third-editions">
<h2>Changes in the second and third editions<a class="headerlink" href="#changes-in-the-second-and-third-editions" title="Link to this heading">¶</a></h2>
<p>The second edition was a minor update correcting numerous small issues that have
been pointed out over the last year. A more substantive change was that the
explanation of packaging in <a class="reference internal" href="2_programs_in_files.html#programs-files"><span class="std std-numref">Section 2</span></a> was modernised to use
<code class="file docutils literal notranslate"><span class="pre">pyproject.toml</span></code> in place of <code class="xref py py-obj docutils literal notranslate"><span class="pre">setup.py</span></code>.
<a class="reference internal" href="3_objects.html#assignment-and-instantiation"><span class="std std-numref">Section 3.5</span></a> was added in response to confusion
expressed by a number of students about the distinction between instantiating
new objects and assigning new variable names to existing objects.</p>
<p>The third edition is similarly a minor update. In documents Visual Studio Code
workspaces in <a class="reference internal" href="2_programs_in_files.html#workspaces"><span class="std std-numref">Section 2.2.1</span></a>, and the Flake8 extension in
<a class="reference internal" href="4_style.html#flake8-extension"><span class="std std-numref">Section 4.2.2</span></a>. Together, these provide correctly integrated code
linting. It also consistently uses <code class="xref py py-obj docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span></code> to invoke tools such as <code class="xref py py-obj docutils literal notranslate"><span class="pre">pip</span></code>,
<a class="reference external" href="https://docs.pytest.org/en/latest/index.html#module-pytest" title="(in pytest v9.1.0.dev134)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">pytest</span></code></a> and <code class="xref py py-obj docutils literal notranslate"><span class="pre">flake8</span></code>. This is less error-prone for students. The description
of <a class="reference external" href="https://docs.python.org/3/reference/compound_stmts.html#finally" title="(in Python v3.14)"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">finally</span></code></a> in <a class="reference internal" href="6_exceptions.html#else-finally"><span class="std std-numref">Section 6.5.2</span></a> has been also improved.</p>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer" role="contentinfo">
© Copyright 2019-2023, David A. Ham.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.4.7.
</div>
</body>
</html>