Skip to content

Commit 6249135

Browse files
committed
several improvements and more examples of exception handling
1 parent 8c9d4a9 commit 6249135

File tree

15 files changed

+138
-38
lines changed

15 files changed

+138
-38
lines changed

scripts/pdflatex.sh

+11-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ echo "$(date +'%0Y-%0m-%0d %0R:%0S'): We will now perform runs of the tool chain
121121
watchFileContents=""
122122
oldWatchFileContents="old"
123123
cycle=0
124+
additional=1
124125

125-
while [ "$watchFileContents" != "$oldWatchFileContents" ] ; do
126+
while (("$additional" >= 0)) ; do
126127
cycle=$((cycle+1))
127128
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): Now beginning build cycle $cycle."
128129

@@ -238,9 +239,17 @@ while [ "$watchFileContents" != "$oldWatchFileContents" ] ; do
238239
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): Something odd is happening: We have performed $cycle cycles. That's too many. Let's quit."
239240
break
240241
fi
242+
243+
if [ "$watchFileContents" != "$oldWatchFileContents" ] ; then
244+
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): Auxiliary file contents changed. We need more cycles."
245+
additional=1
246+
else
247+
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): Auxiliary file contents did not change. We do $additional more cycle(s)."
248+
additional=$(($additional-1))
249+
fi
241250
done
242251

243-
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): The tool chain has been applied until nothing changed anymore. We now check for errors."
252+
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): The tool chain has been applied until nothing changed anymore (after $cycle cycles). We now check for errors."
244253

245254
latexWarningsCount=0
246255
latexWarningString=""

text/back/scripts.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
\Cref{lst:bash:pylint} offers exactly the same functionality for \pylint.
6262
It checks if this tool is installed and installs it if not.
6363
It then applies \pylint\ to a the selected set of files, using a reasonable default configuration.
64-
\Cref{exec:loops:for_loop_no_enumerate:pylint} is an example for the output of this \pgls{linter}.
64+
\Cref{exec:loops:for_loop_no_enumerate:pylint} is an example of the output of this \pgls{linter}.
6565

6666
\Cref{lst:bash:pytest} is similarly structured, but instead of performing \emph{static} code analysis, it executes unit test cases.
6767
The directory and list of \python\ files with the test cases are provided as command line arguments.

text/main/basics/collections/dictionaries/dictionaries.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
\label{sec:dictionaries}%
33
%
44
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{02_collections}{dicts_1.py}{--args format}{dicts:dicts_1}{%
5-
An example for using dictionaries in \python.}%
5+
An example of using dictionaries in \python.}%
66
%
77
Dictionaries in \python\ are containers that store key-value pairs.
88
The value associated with a given key is accessed via the \pythonil{[...]}\pythonIdx{[\idxdots]}-based indexing.

text/main/basics/collections/lists/lists.tex

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
A first example for using lists in \python: creating, indexing, printing of and appending elements and other lists to lists.}%
1212
%
1313
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{02_collections}{lists_2.py}{--args format}{lists:lists_2}{%
14-
A second example for using lists in \python: inserting and deleting elements, sorting and reversing lists.}%
14+
A second example of using lists in \python: inserting and deleting elements, sorting and reversing lists.}%
1515
%
1616
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{02_collections}{lists_3.py}{--args format}{lists:lists_3}{%
17-
A third example for using lists in \python: slicing, adding, and multiplying lists.}%
17+
A third example of using lists in \python: slicing, adding, and multiplying lists.}%
1818
%
1919
In \cref{lst:lists:lists_1}, we provide some first examples for using lists.
2020
A list can be defined by simply writing its contents, separated by~\pythonilIdx{,} inside square brackets~\pythonil{[...]}\pythonIdx{[\idxdots]}.
@@ -140,7 +140,7 @@
140140
\FloatBarrier%
141141
\endhsection%
142142
%
143-
\hsection{An Example for Errors and a new Tool}%
143+
\hsection{An Example of Errors and a new Tool}%
144144
\label{sec:listExampleForErrorsAndRuff}%
145145
%
146146
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{02_collections}{lists_error.py}{--args format}{lists:lists_error}{%

text/main/basics/collections/sets/sets.tex

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
\label{sec:sets}%
33
%
44
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{02_collections}{sets_1.py}{--args format}{sets:sets_1}{%
5-
A first example for using sets in \python: creating, modifying, and converting sets. %
5+
A first example of using sets in \python: creating, modifying, and converting sets. %
66
Since sets are unordered, printing them can yield a different result each time a program is executed (see \cref{bp:setsUnordered}).}%
77
%
88
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{02_collections}{sets_2.py}{--args format}{sets:sets_2}{%
9-
A second example for using sets in \python: creating sets and set operations (as illustrated in \cref{fig:setOperations}). %
9+
A second example of using sets in \python: creating sets and set operations (as illustrated in \cref{fig:setOperations}). %
1010
Since sets are unordered, printing them can yield a different result each time a program is executed (see \cref{bp:setsUnordered}).}%
1111
%
1212
\begin{figure}%
@@ -50,7 +50,7 @@
5050
If we have more than just very few elements and/or need to perform set operations such as those discussed in the following text, sets are the way to go.%
5151
%
5252
\begin{sloppypar}%
53-
In \cref{lst:sets:sets_1}, we provide a first example for creating and working with sets.
53+
In \cref{lst:sets:sets_1}, we provide a first example of creating and working with sets.
5454
Sets can be created by using curly braces, i.e, \pythonil{\{...\}}\pythonIdx{\textbraceleft\idxdots\textbraceright!set}.
5555
They can be type-hinted using the notation \pythonil{set[elementType]}\pythonIdx{set!type hint} where \pythonil{elementType} is the type of elements to be stored in the set~\cite{PEP585}.
5656
The line \pythonil{upper: set[str] = \{"A", "G", "B", "T", "V"\}} creates the variable \pythonil{upper}, which points to a set of the five uppercase latin characters~\pythonil{"A"}, \pythonil{"G"}, \pythonil{"B"}, \pythonil{"T"}, and~\pythonil{"V"}.

text/main/basics/collections/tuples/tuples.tex

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
\label{sec:tuples}%
33
%
44
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{02_collections}{tuples_1.py}{--args format}{tuples:tuples_1}{%
5-
A first example for using tuples in \python: creating, indexing, and printing of tuples.}%
5+
A first example of using tuples in \python: creating, indexing, and printing of tuples.}%
66
%
77
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{02_collections}{tuples_2.py}{--args format}{tuples:tuples_2}{%
8-
A second example for using tuples in \python: tuples with elements of different types and tuple unpacking.}%
8+
A second example of using tuples in \python: tuples with elements of different types and tuple unpacking.}%
99
%
1010
\gitPythonAndErrorOutput{\programmingWithPythonCodeRepo}{02_collections}{tuples_3.py}{--args format}{tuples:tuples_3}{%
11-
A third example for using tuples in \python: testing the immutability property.}%
11+
A third example of using tuples in \python: testing the immutability property.}%
1212
%
1313
\gitOutputTool{\programmingWithPythonCodeRepo}{.}{scripts/mypy.sh 02_collections tuples_3.py}{tuples:tuples_3:mypy}{%
1414
The results of static type checking with \mypy\ of the program given in \cref{lst:tuples:tuples_3}.}%

text/main/basics/gettingStarted/pythonInTheTerminal/pythonInTheTerminal.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
\label{fig:terminalPython3result}%
2727
]{\includegraphics[width=0.9\linewidth]{\currentDir/terminalPython3result}}%
2828
%
29-
\caption{Example for executing a \python\ program in a \pgls{terminal} (on \ubuntu).}%
29+
\caption{Example of executing a \python\ program in a \pgls{terminal} (on \ubuntu).}%
3030
\label{fig:terminalPython}%
3131
\end{figure}%
3232
%

text/main/basics/simpleDataTypesAndOperations/float/float.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
They are off by \emph{less than~$10^{-15}$} so for all practical concerns, they are close enough.
135135
Sometimes, we even get the accurate result, e.g., when computing $\ln(e^{10})$ by evaluating \pythonil{log(e ** 10)}\pythonIdx{log}, which results in~\pythonil{10.0}.
136136

137-
As final example for floating point arithmetics, let us import the inverse trigonometric functions by doing \pythonil{from math import asin, acos, atan}\pythonIdx{math}\pythonIdx{asin}\pythonIdx{acos}\pythonIdx{atan}.
137+
As final example of floating point arithmetics, let us import the inverse trigonometric functions by doing \pythonil{from math import asin, acos, atan}\pythonIdx{math}\pythonIdx{asin}\pythonIdx{acos}\pythonIdx{atan}.
138138
Obviously, $\arcsin{\sin{0.925}}$ should be~$0.925$.
139139
Calculating \pythonil{asin(sin(0.925))}\pythonIdx{asin}\pythonIdx{sin} indeed yields~\pythonil{0.9250000000000002}.
140140
Due to the periodicity of the trigonometric functions, $\arccos{\cos{-0.3}}$ is~$0.3$ and \pythonil{acos(cos(-0.3))}\pythonIdx{acos}\pythonIdx{cos} results in~\pythonil{0.30000000000000016}.

text/main/basics/variables/assignment/assignment.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
You can define a variable and assign its value by writing \pythonil{name = value}.
66
Here, \pythonil{name} is the name of the variable and \pythonil{value} be the value that we want to assign to that name.%
77
%
8-
\hsection{A Simple Example for Variable Assignment and Comments in the Code}%
8+
\hsection{A Simple Example of Variable Assignment and Comments in the Code}%
99
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{01_variables}{assignment.py}{--args format}{variables:assignment}{%
1010
A \python\ program showing some examples for variable assignments.}%
1111
%

text/main/basics/variables/identity/identity.tex

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
\end{figure}%
2222
%
2323
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{01_variables}{identity_1.py}{--args format}{variables:identity_1}{%
24-
An example for the difference between equality and identity\pythonIdx{sqrt}.}%
24+
An example of the difference between equality and identity\pythonIdx{sqrt}.}%
2525
%
2626
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{01_variables}{identity_2.py}{--args format}{variables:identity_2}{%
27-
An second example for the difference between equality and identity.}%
27+
An second example of the difference between equality and identity.}%
2828
%
2929
We use variables to references objects in memory.
3030
When we compare two variables, we actually compare the objects they reference.
@@ -51,7 +51,7 @@
5151
If I would declare a variable \pythonil{d = a}, then \pythonil{d} would point to exactly the same \pythonil{float} object as~\pythonil{a}.
5252
Now, both \pythonil{a == b} and \pythonil{a is b} are \pythonil{True}.
5353

54-
A simple example for the difference between equality and identity is given in \cref{lst:variables:identity_1}.
54+
A simple example of the difference between equality and identity is given in \cref{lst:variables:identity_1}.
5555
Here, we declare a \pythonil{float} variable and store in it the value of~$\sqrt{2}$ (as exactly as it can be represented by a \python\ \pythonil{float}, that is), which just so happens to be \pythonil{1.4142135623730951}.
5656
We then import the function \pythonilIdx{sqrt} from the \pythonilIdx{math} module and compute~\pythonil{sqrt(2.0)}.
5757
We store the result of this in a second variable, namely \pythonil{sqrt_2_computed}.
@@ -66,7 +66,7 @@
6666
First-time readers are welcome to skip over the rest of this subsection.%
6767
}%
6868
%
69-
A slightly more involved example for the issue of object equality and identity is given in \cref{lst:variables:identity_2}.
69+
A slightly more involved example of the issue of object equality and identity is given in \cref{lst:variables:identity_2}.
7070
You see, when the \python\ interpreter parses the program code file, it will allocate the memory and store the values of constants and literals.
7171
\cref{lst:variables:identity_2}, we declare \pythonil{a = "Hello World!"} and then \pythonil{b = "Hello World!"}.
7272
In other words, \pythonil{a} and \pythonil{b} will receive the same value.

text/main/basics/variables/typesAndTypeHints/typesAndTypeHints.tex

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
%
44
\hsection{Variable Types}%
55
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{01_variables}{variable_types.py}{--args format}{variables:types}{%
6-
An example for the types of variables.}%
6+
An example of the types of variables.}%
77
%
88
A variable is basically a name pointing to an object.
99
Each object has a type and we already learned about several of these datatypes in \cref{sec:simplyDataTypesAndOperations}.
@@ -16,7 +16,7 @@
1616
\hsection{Types and Confusion}%
1717
\label{sec:typesAndConfusion}%
1818
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{01_variables}{variable_types_wrong.py}{--args format}{variables:types_wrong}{%
19-
An example for the confusing variable types.}
19+
An example of the confusing variable types.}
2020

2121
Well, actually, there is.
2222
You see, when you declare a variable in a language like \pgls{C}, you have to specify its \emph{type}.

text/main/controlFlow/conditionals/conditionals.tex

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
%
2424
\FloatBarrier%
2525
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{03_conditionals}{if_example.py}{--args format}{conditionals:if}{%
26-
An example for using the \pythonilIdx{if} statement.}%
26+
An example of using the \pythonilIdx{if} statement.}%
2727
%
2828
The first line begins with \pythonilIdx{if}~statement, followed by a Boolean expression, followed by a colon~(\pythonilIdx{:}).
2929
If -- and only if -- the Boolean expression evaluates to~\pythonilIdx{True}, then the \emph{indented} block of statements below the \pythonil{if} are executed.
@@ -66,10 +66,10 @@
6666
\hsection{The \texttt{if}\idxdots\texttt{else} Statement}%
6767
%
6868
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{03_conditionals}{if_else_example.py}{--args format}{conditionals:if_else}{%
69-
An example for using the \pythonil{if ... else}\pythonIdx{if{\idxdots}else} statement.}%
69+
An example of using the \pythonil{if ... else}\pythonIdx{if{\idxdots}else} statement.}%
7070
%
7171
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{03_conditionals}{if_else_nested.py}{--args format}{conditionals:if_else_nested}{%
72-
An example for using nested \pythonil{if ... else}\pythonIdx{if{\idxdots}else!nested} statements.}%
72+
An example of using nested \pythonil{if ... else}\pythonIdx{if{\idxdots}else!nested} statements.}%
7373
%
7474
The ability to perform some action if a given expression evaluates to \pythonil{True} is already nice.
7575
However, often we want to perform some action if the expression evaluates to \pythonil{True} and another action otherwise.
@@ -136,13 +136,13 @@
136136
\hsection{The \texttt{if}\idxdots\texttt{elif}\idxdots\texttt{else} Statement}%
137137
%
138138
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{03_conditionals}{if_elif_example.py}{--args format}{conditionals:if_elif}{%
139-
An example for using the \pythonil{if ... elif}\pythonIdx{if{\idxdots}elif{\idxdots}else} statement.}%
139+
An example of using the \pythonil{if ... elif}\pythonIdx{if{\idxdots}elif{\idxdots}else} statement.}%
140140
%
141141
\gitOutputTool{\programmingWithPythonCodeRepo}{.}{scripts/ruff.sh 03_conditionals if_else_nested.py}{conditionals:if_else_nested:ruff}{%
142142
The results of linting with \ruff\ of the program given in \cref{lst:conditionals:if_else_nested}.}%
143143
%
144144
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{03_conditionals}{if_elif_nested.py}{--args format}{conditionals:if_elif_nested}{%
145-
An example for using the nested \pythonil{if ... elif}\pythonIdx{if{\idxdots}elif{\idxdots}else!nested} statement based on the recommendations of the \ruff\ \pgls{linter} applied to \cref{lst:conditionals:if_else_nested}.}%
145+
An example of using the nested \pythonil{if ... elif}\pythonIdx{if{\idxdots}elif{\idxdots}else!nested} statement based on the recommendations of the \ruff\ \pgls{linter} applied to \cref{lst:conditionals:if_else_nested}.}%
146146
%
147147
%
148148
In some cases, we need to query a sequence of alternatives in such a way that \pythonilIdx{else}~blocks would be nested over \pythonilIdx{else}~blocks over \pythonilIdx{else}~blocks, and so on.
@@ -218,14 +218,14 @@
218218
\label{sec:inlineIfThenElse}%
219219
%
220220
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{03_conditionals}{if_else_could_be_inline.py}{--args format}{conditionals:if_else_could_be_inline}{%
221-
An example for using the nested \pythonil{if ... else}\pythonIdx{if{\idxdots}elif{\idxdots}else} statements that could be inlined. %
221+
An example of using the nested \pythonil{if ... else}\pythonIdx{if{\idxdots}elif{\idxdots}else} statements that could be inlined. %
222222
See \cref{lst:conditionals:inline_if_else} for the more compact inlined variant.}%
223223
%
224224
\gitOutputTool{\programmingWithPythonCodeRepo}{.}{scripts/ruff.sh 03_conditionals if_else_could_be_inline.py}{conditionals:if_else_could_be_inline:ruff}{%
225225
The results of linting with \ruff\ of the program given in \cref{lst:conditionals:if_else_could_be_inline}.}%
226226
%
227227
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{03_conditionals}{inline_if_else.py}{--args format}{conditionals:inline_if_else}{%
228-
An example for using the inline \pythonil{if ... else}\pythonIdx{if{\idxdots}else!inline} expression to shorten \cref{lst:conditionals:if_else_could_be_inline}, which incorporates the suggestion by \ruff\ in \cref{exec:conditionals:if_else_could_be_inline:ruff}.}%
228+
An example of using the inline \pythonil{if ... else}\pythonIdx{if{\idxdots}else!inline} expression to shorten \cref{lst:conditionals:if_else_could_be_inline}, which incorporates the suggestion by \ruff\ in \cref{exec:conditionals:if_else_could_be_inline:ruff}.}%
229229
%
230230
A very common use case of \pythonil{if...else}~statements is to assign values to variables.
231231
In \cref{lst:conditionals:if_else_could_be_inline} we display such a situation.
@@ -269,7 +269,7 @@
269269
Before this, we could only perform straightforward computations and calculate the results of simple functions.
270270
Now our variables can receive the result of a function~$A$ if the input meets a condition~$B$ and otherwise the result of a function~$C$.
271271
This is already quite nice.
272-
For example, we can now implement and hard-code decision trees~\cite{RN2022AIAMA,SSBD2014UMLFTTA} and \cref{lst:conditionals:if_elif} is basically an example for that.
272+
For example, we can now implement and hard-code decision trees~\cite{RN2022AIAMA,SSBD2014UMLFTTA} and \cref{lst:conditionals:if_elif} is basically an example of that.
273273
Still, the instructions in our programs are still executed in the sequence in which we wrote them down.
274274
While our control flow can now branch, it cannot perform anything more fancy and advanced {\dots} like looping back upon itself\dots%
275275
\endhsection%

0 commit comments

Comments
 (0)