Skip to content

Commit 1428a5e

Browse files
committed
more fixes to the first couple of chapters
1 parent 343dde3 commit 1428a5e

File tree

3 files changed

+73
-39
lines changed

3 files changed

+73
-39
lines changed

doc/source/0_preface.rst

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Preface
22
=======
33

4-
Computers have revolutionised mathematics, as well as the many scientific,
5-
engineering and economic fields in which mathematics is applied. In
6-
the applications of mathematics the role of computation has long been obvious
7-
and prominent. Now, the development of theorem proving software is increasing
8-
the prominence of computing in pure mathematics. What this means is that
9-
the ability to write computer programs is an indispensible part of the toolkit
10-
of a 21st century mathematician and, indeed, scientist or engineer.
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.
1111

1212
Regrettably, university courses in mathematics and its sibling disciplines have
1313
often failed to reflect this revolution in the way that mathematics is
@@ -37,9 +37,10 @@ year courses with the sole objective of teaching students to programme well.
3737
This book is the text for the second of these courses. Named "Principles of
3838
Programming", the course aims to take students with a knowledge of basic Python
3939
programming (functions, loops, plotting and so forth) and introduce them to
40-
higher level programming concepts. The course has also been taught to masters
40+
higher level programming concepts. The course has also been taught to master's
41+
students in the Mathematical Institute at the University of Oxford.
4142

42-
The objective of this course is to graduate better programmers, so material on
43+
The objective of this course is to graduate better programmers. Material on
4344
new programming constructs and concepts is accompanied by chapters on good
4445
programming style, so that students learn how to write code that they and
4546
others can understand, and on errors, exceptions and debugging, so that
@@ -66,12 +67,19 @@ Who is this book for?
6667
This book is for anyone with mathematical, scientific, or engineering interests
6768
who would like to learn to be a more capable programmer. The mathematical
6869
examples assume that you know how to differentiate functions of one variable,
69-
but very little beyond that. This is not an introduction to basic Python: it's
70-
assumed that the reader knows the sort of basic Python usually covered in a
71-
first programming or computational methods course. In particular the reader
72-
will be assumed to be familiar with writing functions, variable assignments,
73-
loops, and list comprehensions. The reader is also assumed to have used numeric
74-
and string data values, as well as dictionaries, lists, and tuples.
70+
but very little beyond that. Where examples or exercises employ other
71+
mathematics, such as cellular automata in :numref:`style` and groups in
72+
:numref:`abstract_data_types`, enough of the mathematics will be introduced
73+
that the reader should be able to understand the programming concept being
74+
explained, without necessarily understanding all of the mathematical details of
75+
the example.
76+
77+
This is not an introduction to basic Python: it's assumed that the reader knows
78+
the sort of basic Python usually covered in a first programming or
79+
computational methods course. In particular the reader will be assumed to be
80+
familiar with writing functions, variable assignments, loops, and list
81+
comprehensions. The reader is also assumed to have used numeric and string data
82+
values, as well as dictionaries, lists, and tuples.
7583

7684
Many introductory Python courses exclusively use Jupyter notebooks, so nothing
7785
beyond that is assumed. Getting set up with a working Python installation is

doc/source/1_introduction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ therefore make you a better user of that software. The second is that
5858
making appropriate use of abstractions will make you a better
5959
programmer of mathematics and other software. Applied well, objects
6060
and abstraction produce software which is easier to write, easier to
61-
understand, easier to debug and easier to extend. Indeed, as with
61+
understand, easier to debug, and easier to extend. Indeed, as with
6262
abstraction in mathematics, abstraction in coding is a form of
6363
constructive laziness: it simultaneously allows the mathematician to
6464
achieve more and do less work.

doc/source/2_programs_in_files.rst

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ program is read and executed by another piece of software, the Python
3636
interpreter. The Python interpreter takes a sequence of Python statements and
3737
performs the actions they specify. The interpreter takes care of allocating the
3838
required memory and causes the right sequences of primitive machine-level
39-
instructions to execute on the actual hardware for your programme to run.
39+
instructions to execute on the actual hardware such that your programme runs.
4040

4141
The Python interpreter is the same no matter whether you use Jupyter
4242
notebooks, an interactive Python terminal such as IPython, or execute
@@ -85,7 +85,7 @@ This will result in output simiar to the following:
8585
8686
In [1]:
8787
88-
Just like in a Jupyter notebook, this last line is the Python prompt at which
88+
Just as in a Jupyter notebook, this last line is the Python prompt at which
8989
you can type any Python you like. If you press return after a complete Python
9090
statement, the statement will execute immediately. Unlike in a Jupyter
9191
notebook, there is no special key combination or button to trigger execution.
@@ -104,8 +104,8 @@ and edit Python files with a program called a text editor. A good text
104104
editor will help you to code by highlighting syntax and helping with
105105
indentation. Some text editors also feature advanced features such as
106106
built-in access to documentation, or highlighting style problems in
107-
your code. A more fully-featured option is an Integrated Development
108-
Environment (IDE). IDEs combine an editor with a Python interpreter to
107+
your code. A more fully-featured option is an :term:`integrated development
108+
environment` (IDE). IDEs combine an editor with a Python interpreter to
109109
run your code, a debugger and often other features such as integration
110110
with Git.
111111

@@ -394,8 +394,16 @@ from the module (without any warning or error). This is a frequent
394394
source of confusion. For this reason, importing `*` is usually a bad
395395
idea.
396396

397-
The full details of all the ways that the import statement can be used
398-
is in :ref:`the official Python documentation. <python:import>`
397+
.. only:: not book
398+
399+
The full details of all the ways that the import statement can be used
400+
is in :ref:`the official Python Language Reference. <python:import>`
401+
402+
.. only:: book
403+
404+
The full details of all the ways that the import statement can be used
405+
is in the official Python Language Reference. [#import]_
406+
399407

400408
Packages
401409
--------
@@ -577,11 +585,22 @@ about all of the packages in the current repository, but this can be
577585
automated with the :func:`~setuptools.find_packages` function, which
578586
will return a list of folders containing a file named :file:`__init__.py`.
579587

580-
This very simple :file:`setup.py` will suffice for packages that you only
581-
intend to use yourself. Should you wish to publish packages for use by
582-
other people, then you'll need to add some more information to the
583-
file. The canonical guide to this is the `Python Packaging User Guide
584-
<https://packaging.python.org/tutorials/packaging-projects/>`__.
588+
.. only:: not book
589+
590+
This very simple :file:`setup.py` will suffice for packages that you only
591+
intend to use yourself. Should you wish to publish packages for use by other
592+
people, then you'll need to provide significantly more information in
593+
:file:`setup.py` and, potentially, in other places too. The canonical guide to
594+
this is the `Python Packaging User Guide
595+
<https://packaging.python.org/tutorials/packaging-projects/>`__.
596+
597+
.. only:: book
598+
599+
This very simple :file:`setup.py` will suffice for packages that you only
600+
intend to use yourself. Should you wish to publish packages for use by
601+
other people, then you'll need to provide significantly more information in
602+
:file:`setup.py` and, potentially, in other places too. The canonical guide
603+
to this is the Python Packaging User Guide. [#packaging]_
585604

586605
Installing a package from local code
587606
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -687,7 +706,7 @@ including tests in your code here.
687706

688707
There are a number of Python packages which support code testing. The concepts
689708
are largely similar so rather than get bogged down in the details of multiple
690-
frameworks, we will introduce :doc:`pytest <pytest:index>`, which is one of the
709+
frameworks, we will introduce :doc:`Pytest <pytest:index>`, which is one of the
691710
most widely used. Pytest is simply a Python package, so you can install it into
692711
your current environment using:
693712

@@ -798,11 +817,11 @@ wrong. We will learn how to interpret this output in :numref:`Chapter %s
798817
<errors_and_exceptions>`.
799818

800819

801-
Additional useful pytest tricks
820+
Additional useful Pytest tricks
802821
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
803822

804823
It can be useful to run a specific test file, which is achieved simply by naming
805-
that file as the argument to pytest. For example:
824+
that file as the argument to Pytest. For example:
806825

807826
.. code-block:: console
808827
@@ -818,7 +837,7 @@ It is even possible to select an individual test to run, using a double colon
818837
Often if one test fails then the same problem in your code will cause a whole
819838
series of tests to fail, resulting in a very long list of error messages which
820839
is hard to read. A useful tool in this circumstance is the `-x` option, which
821-
tells pytest to stop after the first test fail. For example:
840+
tells Pytest to stop after the first test fail. For example:
822841

823842
.. code-block:: console
824843
@@ -831,12 +850,12 @@ only move onto the next problem when the previous test passes.
831850

832851
.. note::
833852

834-
The exercise repositories provided here will contain a :file:`tests` folder
835-
full of tests that check that you have correctly implemented the week's
836-
exercises. You should get in the habit of running the tests as you work
837-
through the exercises, as they are designed not just to pass if your code
838-
is correct, but to provide feedback as to what might be going wrong if your
839-
code contains errors.
853+
The exercise repositories that accompany this book will contain a
854+
:file:`tests` folder full of tests that check that you have correctly
855+
implemented the chaper's exercises. You should get in the habit of running
856+
the tests as you work through the exercises, as they are designed not just
857+
to pass if your code is correct, but to provide feedback as to what might
858+
be going wrong if your code contains errors.
840859

841860
Writing code to a specified interface
842861
-------------------------------------
@@ -937,7 +956,7 @@ Exercises
937956
<https://github.com/object-oriented-python/object-oriented-programming>`__.
938957
Clone that git repository into your course folder, and install the Python
939958
package it contains into your virtual environment. Check that it has
940-
installed correctly by installing pytest, and running:
959+
installed correctly by installing Pytest, and running:
941960

942961
.. code-block:: console
943962
@@ -1008,4 +1027,11 @@ Exercises
10081027
10091028
.. rubric:: Footnotes
10101029

1011-
.. [#peters] Tim Peters, `"PEP 20 -- The Zen Of Python" (2004) <https://www.python.org/dev/peps/pep-0020/>`__
1030+
.. [#peters] Tim Peters, `"PEP 20 -- The Zen Of Python" (2004)
1031+
<https://www.python.org/dev/peps/pep-0020/>`__
1032+
1033+
.. [#import] `https://docs.python.org/3/reference
1034+
<https://docs.python.org/3/reference/simple_stmts.html#import>`__
1035+
1036+
.. [#packaging] `https://packaging.python.org
1037+
<https://packaging.python.org/tutorials/packaging-projects/>`__

0 commit comments

Comments
 (0)