Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132930 views
License: OTHER
1
\documentclass{beamer}
2
\usetheme{Feather}
3
% \usecolortheme{default}
4
\usepackage{hyperref}
5
\definecolor{links}{HTML}{2A1B81}
6
\definecolor{green}{HTML}{008000}
7
\hypersetup{colorlinks,linkcolor=,urlcolor=links}
8
\usepackage[utf8]{inputenc} % this is needed for german umlauts
9
\usepackage[english]{babel} % this is needed for german umlauts
10
\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
11
\usepackage{pifont}
12
\usepackage{graphicx}
13
\usepackage{minted} % needed for the inclusion of source code
14
\usepackage{csquotes}
15
16
17
\newcommand{\FolderOpen}[1][.8\ht\strutbox]{%
18
\includegraphics[height=#1]{graphics/FolderOpen}%
19
}
20
21
\newcommand{\FileImage}[1][.8\ht\strutbox]{%
22
\includegraphics[height=#1]{graphics/file}%
23
}
24
25
\begin{document}
26
27
\title{Software Engineering Basics}
28
% \subtitle{A subtitle}
29
\author{Martin Thoma}
30
\date{14. August 2018}
31
\subject{Software Engineering}
32
33
\frame{\titlepage}
34
35
\section{Intended Audience}
36
\subsection{A subsection!}
37
\begin{frame}{Intended Audience}
38
Software is written by people with different backgrounds and strengths. Not
39
everybody has a Software Engineering background. Those slides should help
40
you to get the basics.
41
\end{frame}
42
43
\subsection{A subsection!}
44
\begin{frame}{Alice and Bob}
45
\begin{columns}
46
\begin{column}{0.5\textwidth}
47
\includegraphics[width=1.0\textwidth]{graphics/car.jpg}
48
\end{column}
49
\begin{column}{0.5\textwidth}
50
\begin{itemize}
51
\item Project: Build self-driving car
52
\item Alice is in the US, Bob in Germany
53
\end{itemize}
54
\end{column}
55
\end{columns}
56
\end{frame}
57
58
% \subsection{Version Control}
59
\begin{frame}{Project structure}
60
\begin{columns}
61
\begin{column}{0.5\textwidth}
62
\begin{itemize}
63
\item[\FolderOpen] bin
64
\item[\FolderOpen] docs
65
\item[\FolderOpen] awesome\_project
66
\item[\FolderOpen] tests
67
\item[\FileImage] setup.py
68
\item[\FileImage] tox.ini
69
\end{itemize}
70
\end{column}
71
\begin{column}{0.5\textwidth}
72
\begin{itemize}
73
\item[\textcolor{green}{\ding{58}}] \texttt{\$ grep -rnIi foobar}
74
\end{itemize}
75
Details on \href{https://martin-thoma.com/python-projects/}{my blog}.
76
\end{column}
77
\end{columns}
78
\end{frame}
79
80
\begin{frame}{git workflow}
81
\begin{enumerate}
82
\item \texttt{\$ git clone repostory.git}
83
\item \texttt{\$ git add filename}
84
\item \texttt{\$ git commit}
85
\item \texttt{\$ git push}
86
\end{enumerate}
87
88
\uncover<2>{\includegraphics[width=1.0\textwidth,height=0.5\textheight,keepaspectratio]{graphics/git-workflow.png}}
89
\end{frame}
90
91
\begin{frame}{Version Control: git}
92
\includegraphics[width=1.0\textwidth]{graphics/git-simple.png}
93
\end{frame}
94
95
\begin{frame}{git log}
96
\includegraphics[width=0.9\textwidth]{graphics/git-log.png}
97
\end{frame}
98
99
\begin{frame}{git blame}
100
\includegraphics[width=1.0\textwidth]{graphics/git-blame.png}
101
\end{frame}
102
103
\begin{frame}{git status}
104
\includegraphics[width=1.0\textwidth]{graphics/git-status.png}
105
\end{frame}
106
107
\begin{frame}{}
108
\huge We read code MUCH more often than we write it.
109
\end{frame}
110
111
\begin{frame}{git}
112
Problem: Dirty commit history due to bugs / fixes
113
\includegraphics[width=1.0\textwidth]{graphics/git-2-fixes.png}
114
\end{frame}
115
116
\begin{frame}{Auto formatting}
117
\begin{itemize}[<+->]
118
\item PRs should not be about simple code style
119
\item Choose one \href{https://martin-thoma.com/python-style-guide/}{style guide}
120
and stick to it
121
\item Trailing spaces are just noise - make your editor remove them
122
automatically.
123
\end{itemize}
124
\end{frame}
125
126
\begin{frame}{The Zen of Python, by Tim Peters (1)}
127
Beautiful is better than ugly.\\
128
Explicit is better than implicit.\\
129
Simple is better than complex.\\
130
Complex is better than complicated.\\
131
Flat is better than nested.\\
132
Sparse is better than dense.\\
133
Readability counts.\\
134
Special cases aren't special enough to break the rules.\\
135
Although practicality beats purity.\\
136
Errors should never pass silently.\\
137
Unless explicitly silenced.
138
\end{frame}
139
140
\begin{frame}{The Zen of Python, by Tim Peters (2)}
141
In the face of ambiguity, refuse the temptation to guess.\\
142
There should be one-- and preferably only one --obvious way to do it.\\
143
Although that way may not be obvious at first unless you're Dutch.\\
144
Now is better than never.\\
145
Although never is often better than *right* now.\\
146
If the implementation is hard to explain, it's a bad idea.\\
147
If the implementation is easy to explain, it may be a good idea.\\
148
Namespaces are one honking great idea -- let's do more of those!
149
\end{frame}
150
151
152
\begin{frame}{commit messages}
153
\begin{columns}
154
\begin{column}{0.5\textwidth}
155
\begin{itemize}[<+->]
156
\item Can I understand what the commit was about?
157
\item Use prefixes
158
\item Mention issues
159
\end{itemize}
160
\end{column}
161
\begin{column}{0.5\textwidth}
162
\only<1>{cleanup, fixed bug, new feature, \dots}
163
\only<2>{
164
165
\begin{itemize}
166
\item BUG: bug fix
167
\item DEV: development tool or utility
168
\item DOC: documentation
169
\item ENH: Enhancement, a new feature
170
\item MAINT: Maintenance task
171
\item REL: release
172
\item STY: Stylistic change
173
\item TST: addition or modification of tests
174
\end{itemize}
175
176
Source: \href{https://docs.scipy.org/doc/numpy-1.13.0/dev/gitwash/development_workflow.html}{Scipy Docs}
177
}
178
\only<3>{
179
\begin{itemize}
180
\item See issue \#123
181
\item Closes issue \#123
182
\end{itemize}
183
}
184
\end{column}
185
\end{columns}
186
\end{frame}
187
188
189
\begin{frame}{commit ammend}
190
\texttt{\$ git commit --amend}
191
192
\begin{itemize}
193
\item Add to last commit / change message
194
\item Only on feature branch as it might require force-push!
195
\end{itemize}
196
\end{frame}
197
198
199
\begin{frame}{commit squashing}
200
\begin{columns}
201
\begin{column}{0.5\textwidth}
202
\textbf{Commit squashing}
203
204
Making multiple commits in a row become one
205
\end{column}
206
\begin{column}{0.5\textwidth}
207
\includegraphics[height=0.5\textheight]{graphics/commit-squashing.png}
208
{\small Image source: \href{https://stevenschwenke.de/GitToSquashOrNotToSquash}{stevenschwenke.de}}
209
\end{column}
210
\end{columns}
211
\end{frame}
212
213
\begin{frame}{git merge}
214
\includegraphics[width=1.0\textwidth,height=0.5\textheight,keepaspectratio]{graphics/git-merge.png}
215
\end{frame}
216
217
\begin{frame}{git merge vs git rebase}
218
\includegraphics[width=1.0\textwidth,height=0.8\textheight,keepaspectratio]{graphics/git-rebase.png}
219
220
{\small Image source: \href{https://jeffkreeftmeijer.com/git-rebase/}{Jeff Kreeftmeijer}}
221
\end{frame}
222
223
224
\section{Bugs}
225
\begin{frame}{Logic Bugs: Functions and McCabe}
226
\inputminted[linenos,
227
numbersep=7pt,
228
fontsize=\footnotesize, tabsize=4]{python}{src/sieve-v1.py}
229
\end{frame}
230
231
\begin{frame}{Logic Bugs: Names}
232
\inputminted[linenos,
233
numbersep=7pt,
234
fontsize=\footnotesize, tabsize=4,
235
firstline=4]{python}{src/sieve-v2.py}
236
\end{frame}
237
238
\begin{frame}{Logic Bugs: Doctests!}
239
\inputminted[linenos,
240
numbersep=7pt,
241
fontsize=\footnotesize, tabsize=4,
242
firstline=8, lastline=24]{python}{src/sieve-v3.py}
243
\end{frame}
244
245
246
\section{Falsehood Data Scientists Beliefes}
247
\begin{frame}{Falsehood Data Scientists Beliefes}
248
\begin{centering}
249
(1) Floating point numbers always look like this: 1.23456 or 0.000004577 or 12345.467765.
250
\end{centering}
251
252
\uncover<2->{
253
\begin{itemize}
254
\item<2-> Scientific notation: \texttt{4.577E-5} or \texttt{1.2345467765E4}
255
\item<3-> German decimal format: \texttt{1,23456} or \texttt{0,000004577}
256
\end{itemize}
257
}
258
\end{frame}
259
260
\begin{frame}{Falsehood Data Scientists Beliefes}
261
\begin{centering}
262
(2.1) Country names have an unique representation
263
\end{centering}
264
265
\uncover<2>{
266
\enquote{Germany} vs \enquote{Deutschland}
267
}
268
\end{frame}
269
270
\begin{frame}{Falsehood Data Scientists Beliefes}
271
\begin{centering}
272
(2.2) Country names have an unique representation in English
273
\end{centering}
274
275
\uncover<2>{
276
\enquote{United Kingdom} vs \enquote{UK}
277
}
278
\end{frame}
279
280
\begin{frame}{Falsehood Data Scientists Beliefes}
281
\begin{centering}
282
(2.3) Country names have an unique unabreviated representation in English
283
\end{centering}
284
285
\uncover<2>{
286
\enquote{United Kingdom} vs \enquote{Great Britain} vs \enquote{England}
287
}
288
\uncover<3>{Solution: Use/Demand \textbf{ISO 3166-1 alpha-3 country codes} everywhere}
289
\end{frame}
290
291
\begin{frame}{Falsehood Data Scientists Beliefes}
292
\begin{centering}
293
(3) Data is clean
294
\end{centering}
295
296
\uncover<2->{
297
No.
298
\begin{itemize}
299
\item<3-> User database: Birth date in the year 3.
300
\item<4-> User database: Active user who is more than 90 years old.
301
\item<5-> User database: User who is younger than 6.
302
\end{itemize}
303
}
304
\end{frame}
305
306
\begin{frame}{Falsehood Data Scientists Beliefes}
307
\begin{centering}
308
(4) Time has no beginning and no end
309
\end{centering}
310
311
\uncover<2->{
312
Unix Time Stamp: Seconds since 1st of January, 1970. Stored in unsigned int.
313
}
314
\end{frame}
315
316
\begin{frame}{Falsehood Data Scientists Beliefes}
317
\begin{centering}
318
(4) To avoid the Year-2038 problem, I can store \texttt{YYYY-mm-dd HH:MM:ss}
319
\end{centering}
320
321
\uncover<2->{
322
\begin{itemize}
323
\item<2-> \href{http://strftime.org/}{Python's strftime directives}
324
\item<3-> Timezones
325
\item<4-> Whenever possible, store the timezone and use \textbf{ISO 8601}:
326
\texttt{2012-04-23T18:25:43.511+02:30} (\href{https://stackoverflow.com/a/15952652/562769}{reasons})
327
\end{itemize}
328
}
329
\end{frame}
330
331
332
\begin{frame}{Falsehood Data Scientists Beliefes}
333
\begin{centering}
334
(5) The (physical) unit of a column / an API can be guessed.
335
\end{centering}
336
337
\uncover<2->{
338
\begin{itemize}
339
\item<2-> Clarify it
340
\item<3-> See if the distribution / quantiles are reasonable
341
\item<4-> Internally, use unit library \href{http://pint.readthedocs.io/en/latest/}{Pint}
342
\end{itemize}
343
}
344
\end{frame}
345
346
347
\begin{frame}{See also}
348
\begin{itemize}
349
\item git
350
\begin{itemize}
351
\item \href{http://meldmerge.org/}{meld}: Tool for diff and merge (\texttt{\$ git mergetool})
352
\item \href{https://nvie.com/posts/a-successful-git-branching-model/}{A successful Git branching model}
353
\end{itemize}
354
\item \href{https://www.youtube.com/watch?v=8SNaW1nt6j0}{Debugging Python with ipdb and Sypder} - starting at 4:00
355
\item \href{https://docs.python.org/3/library/profile.html}{cprofile}: Check where code improvements are effective
356
\item David Goldberg: \href{https://www.itu.dk/~sestoft/bachelor/IEEE754_article.pdf}{What Every Computer Scientist Should Know About Floating-Point Arithmetic}
357
\item \href{https://martin-thoma.com/testing-python-code/}{Testing with Python}
358
\item \href{https://martin-thoma.com/logging-in-python/}{Logging with Python}
359
\item UML: \href{https://www.websequencediagrams.com/}{Sequence diagrams}, Flow charts (e.g. \href{https://wiki.gnome.org/Apps/Dia/}{Dia} or \href{https://www.draw.io/}{draw.io})
360
\item \href{https://balsamiq.com/}{Balsamiq}: Draft an UI
361
\item Web: \href{https://gist.github.com/alexserver/2fcc26f7e1ebcfc9f6d8}{REST basics}
362
\end{itemize}
363
\end{frame}
364
\end{document}
365
Bare excepts are only correct when trying to capture and forward exceptions - in all other cases, except Exception should be used to avoid catching KeyboardInterrupt.
366