You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h1>Preface<aclass="headerlink" href="#preface" title="Permalink to this headline">¶</a></h1>
69
+
<p>Computers have revolutionised mathematics and the many scientific, engineering
70
+
and economic fields in which mathematics is applied. In the applications of
71
+
mathematics the role of computation has long been obvious and prominent. Now,
72
+
the development of theorem proving software is increasing the prominence of
73
+
computing in pure mathematics. What this means is that the ability to write
74
+
computer programs well is an indispensable part of the toolkit of a 21st
75
+
century mathematician and, indeed, scientist or engineer.</p>
76
+
<p>Regrettably, university courses in mathematics and its sibling disciplines have
77
+
often failed to reflect this revolution in the way that mathematics is
78
+
practised. Far too often the sum total of programming education in an
79
+
undergraduate degree is a computational methods module in which students are
80
+
shown elementary programming constructs such as functions, loops, and perhaps
81
+
plotting. These are introduced in the context of solving particular
82
+
computational mathematics or statistics problems, and the programming
83
+
constructs introduced are driven by what is needed to solve those problems.</p>
84
+
<p>The assumptions underpinning this approach seem to be some combination of a
85
+
belief that maths degrees should only teach maths, as well a feeling that the
86
+
mathematical algorithms are some how the difficult part and that programming is
87
+
a mere technical skill that students will somehow pick up along the way. The
88
+
consequence of this approach is that many maths students and graduates end up
89
+
without the programming, software development, and debugging skills that they
90
+
need to make effective use of computers in their further studies or working
91
+
careers.</p>
92
+
<sectionid="what-is-this-book-for">
93
+
<h2>What is this book for?<aclass="headerlink" href="#what-is-this-book-for" title="Permalink to this headline">¶</a></h2>
94
+
<p>This book is the result of a significant change in the mathematics curriculum
95
+
at Imperial College London. Rather than assume that students will somehow
96
+
acquire programming skills along the way, we have introduced first and second
97
+
year courses with the sole objective of teaching students to programme well.
98
+
This book is the text for the second of these courses. Named “Principles of
99
+
Programming”, the course aims to take students with a knowledge of basic Python
100
+
programming (functions, loops, plotting and so forth) and introduce them to
101
+
higher level programming concepts.</p>
102
+
<p>The objective of this course is to graduate better programmers. Material on
103
+
new programming constructs and concepts is accompanied by chapters on good
104
+
programming style, so that students learn how to write code that they and
105
+
others can understand, and on errors, exceptions and debugging, so that
106
+
students learn how to get themselves out of trouble.</p>
107
+
<p>An underlying theme throughout this book is that programming has strong
108
+
connections with mathematics. In particular, both mathematics and programming
109
+
depend on building higher level, more abstract objects which encapsulate and
110
+
hide the underlying complexity of operations. It is in taking this mathematical
111
+
approach to programming that this book is “for mathematicians”.</p>
112
+
<p>The examples are chosen from across mathematics. For example, it appears to be
113
+
traditional in object oriented programming books to use a telephone directory
114
+
as the initial example of classes. We eschew this in favour of a class
115
+
implementing polynomials. This provides the opportunity to introduce
116
+
encapsulation and operator overloading for a familiar mathematical object. In
117
+
contrast to the traditional computational methods courses, the examples are
118
+
chosen to illustrate and explain the programming concepts we study rather than
119
+
the converse.</p>
120
+
</section>
121
+
<sectionid="who-is-this-book-for">
122
+
<h2>Who is this book for?<aclass="headerlink" href="#who-is-this-book-for" title="Permalink to this headline">¶</a></h2>
123
+
<p>This book is for anyone with mathematical, scientific, or engineering interests
124
+
who would like to learn to be a more capable programmer. The mathematical
125
+
examples assume that you know how to differentiate functions of one variable,
126
+
but very little beyond that. Where examples or exercises employ other
127
+
mathematics, such as cellular automata in <aclass="reference internal" href="4_style.html#style"><spanclass="std std-numref">Chapter 4</span></a> and
128
+
groups in <aclass="reference internal" href="5_abstract_data_types.html#abstract-data-types"><spanclass="std std-numref">Chapter 5</span></a>, enough of the mathematics
129
+
will be introduced that the reader should be able to understand the programming
130
+
concept being explained, without necessarily understanding all of the
131
+
mathematical details of the example.</p>
132
+
<p>This is not an introduction to basic Python: it’s assumed that the reader knows
133
+
the sort of basic Python usually covered in a first programming or
134
+
computational methods course. In particular the reader will be assumed to be
135
+
familiar with writing functions, variable assignments, loops, and list
136
+
comprehensions. The reader is also assumed to have used numeric and string data
137
+
values, as well as dictionaries, lists, and tuples.</p>
138
+
<p>Many introductory Python courses exclusively use Jupyter notebooks, so nothing
139
+
beyond that is assumed. Getting set up with a working Python installation is
140
+
covered in <aclass="reference internal" href="1_introduction.html#introduction"><spanclass="std std-numref">Chapter 1</span></a> while the Python command line
141
+
and using a text editor to create programmes in files are introduced from
142
+
scratch in <aclass="reference internal" href="2_programs_in_files.html#programs-files"><spanclass="std std-numref">Chapter 2</span></a>.</p>
143
+
</section>
144
+
<sectionid="how-to-use-this-book">
145
+
<h2>How to use this book<aclass="headerlink" href="#how-to-use-this-book" title="Permalink to this headline">¶</a></h2>
146
+
<p>You can, of course, simply sit down and read this book from cover to cover,
147
+
or dip in to see what it has to say on particular subjects. However,
148
+
reading a book about programming will not teach you to program. For that,
149
+
you need to get your hands dirty writing code and debugging your mistakes.
150
+
The videos and exercises throughout the book are designed to help you do
151
+
this.</p>
152
+
<sectionid="the-videos">
153
+
<h3>The videos<aclass="headerlink" href="#the-videos" title="Permalink to this headline">¶</a></h3>
154
+
<p>The videos were created to accompany the course at Imperial College London.
155
+
They’re not primarily lecture videos but are instead practical demonstrations
156
+
of the programming concepts being introduced at the relevant point. Usually
157
+
it’s better to watch the video <em>after</em> reading the relevant section.</p>
158
+
</section>
159
+
<sectionid="the-exercises">
160
+
<h3>The exercises<aclass="headerlink" href="#the-exercises" title="Permalink to this headline">¶</a></h3>
161
+
<p>At the end of each chapter are exercises. These usually depend on a skeleton
162
+
code which is available on GitHub. Sometimes you might be asked to complete a
163
+
piece of code while on other occasions you’ll need to write a whole Python
164
+
module from scratch. Each set of exercises will come with a matching set of
165
+
tests. These are small programs which check whether your code produces the
166
+
correct responses to a range of inputs. Tests like this provide immediate
167
+
feedback and enable you to know how you are doing. Links to the skeleton code
<h2>Conventions employed<aclass="headerlink" href="#conventions-employed" title="Permalink to this headline">¶</a></h2>
176
+
<p>Each chapter starts by introducing new material, supported by the videos and
177
+
exercises. At the end of each chapter is a glossary containing many of the key
178
+
concepts introduced in that chapter. Terms to be found in a glossary are given
179
+
<em>in italics</em> and can be looked up in the index.</p>
180
+
<p>Python has excellent <aclass="reference external" href="https://docs.python.org/3/">official online documentation</a>, and we link to that throughout the text.
181
+
External links show up in purple while <aclass="reference internal" href="1_introduction.html#introduction"><spanclass="std std-ref">internal links to other parts
182
+
of the notes</span></a> are blue.</p>
183
+
<p>The text sometimes introduces counterexamples: illustrations of code errors or
184
+
bad implementation ideas. These will be flagged with a big red cross:</p>
0 commit comments