📚 The CoCalc Library - books, templates and other resources
cocalc-examples / martinthoma-latex-examples / presentations / software-engineering-basics / software-engineering-basics.tex
132928 viewsLicense: OTHER
\documentclass{beamer}1\usetheme{Feather}2% \usecolortheme{default}3\usepackage{hyperref}4\definecolor{links}{HTML}{2A1B81}5\definecolor{green}{HTML}{008000}6\hypersetup{colorlinks,linkcolor=,urlcolor=links}7\usepackage[utf8]{inputenc} % this is needed for german umlauts8\usepackage[english]{babel} % this is needed for german umlauts9\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf10\usepackage{pifont}11\usepackage{graphicx}12\usepackage{minted} % needed for the inclusion of source code13\usepackage{csquotes}141516\newcommand{\FolderOpen}[1][.8\ht\strutbox]{%17\includegraphics[height=#1]{graphics/FolderOpen}%18}1920\newcommand{\FileImage}[1][.8\ht\strutbox]{%21\includegraphics[height=#1]{graphics/file}%22}2324\begin{document}2526\title{Software Engineering Basics}27% \subtitle{A subtitle}28\author{Martin Thoma}29\date{14. August 2018}30\subject{Software Engineering}3132\frame{\titlepage}3334\section{Intended Audience}35\subsection{A subsection!}36\begin{frame}{Intended Audience}37Software is written by people with different backgrounds and strengths. Not38everybody has a Software Engineering background. Those slides should help39you to get the basics.40\end{frame}4142\subsection{A subsection!}43\begin{frame}{Alice and Bob}44\begin{columns}45\begin{column}{0.5\textwidth}46\includegraphics[width=1.0\textwidth]{graphics/car.jpg}47\end{column}48\begin{column}{0.5\textwidth}49\begin{itemize}50\item Project: Build self-driving car51\item Alice is in the US, Bob in Germany52\end{itemize}53\end{column}54\end{columns}55\end{frame}5657% \subsection{Version Control}58\begin{frame}{Project structure}59\begin{columns}60\begin{column}{0.5\textwidth}61\begin{itemize}62\item[\FolderOpen] bin63\item[\FolderOpen] docs64\item[\FolderOpen] awesome\_project65\item[\FolderOpen] tests66\item[\FileImage] setup.py67\item[\FileImage] tox.ini68\end{itemize}69\end{column}70\begin{column}{0.5\textwidth}71\begin{itemize}72\item[\textcolor{green}{\ding{58}}] \texttt{\$ grep -rnIi foobar}73\end{itemize}74Details on \href{https://martin-thoma.com/python-projects/}{my blog}.75\end{column}76\end{columns}77\end{frame}7879\begin{frame}{git workflow}80\begin{enumerate}81\item \texttt{\$ git clone repostory.git}82\item \texttt{\$ git add filename}83\item \texttt{\$ git commit}84\item \texttt{\$ git push}85\end{enumerate}8687\uncover<2>{\includegraphics[width=1.0\textwidth,height=0.5\textheight,keepaspectratio]{graphics/git-workflow.png}}88\end{frame}8990\begin{frame}{Version Control: git}91\includegraphics[width=1.0\textwidth]{graphics/git-simple.png}92\end{frame}9394\begin{frame}{git log}95\includegraphics[width=0.9\textwidth]{graphics/git-log.png}96\end{frame}9798\begin{frame}{git blame}99\includegraphics[width=1.0\textwidth]{graphics/git-blame.png}100\end{frame}101102\begin{frame}{git status}103\includegraphics[width=1.0\textwidth]{graphics/git-status.png}104\end{frame}105106\begin{frame}{}107\huge We read code MUCH more often than we write it.108\end{frame}109110\begin{frame}{git}111Problem: Dirty commit history due to bugs / fixes112\includegraphics[width=1.0\textwidth]{graphics/git-2-fixes.png}113\end{frame}114115\begin{frame}{Auto formatting}116\begin{itemize}[<+->]117\item PRs should not be about simple code style118\item Choose one \href{https://martin-thoma.com/python-style-guide/}{style guide}119and stick to it120\item Trailing spaces are just noise - make your editor remove them121automatically.122\end{itemize}123\end{frame}124125\begin{frame}{The Zen of Python, by Tim Peters (1)}126Beautiful is better than ugly.\\127Explicit is better than implicit.\\128Simple is better than complex.\\129Complex is better than complicated.\\130Flat is better than nested.\\131Sparse is better than dense.\\132Readability counts.\\133Special cases aren't special enough to break the rules.\\134Although practicality beats purity.\\135Errors should never pass silently.\\136Unless explicitly silenced.137\end{frame}138139\begin{frame}{The Zen of Python, by Tim Peters (2)}140In the face of ambiguity, refuse the temptation to guess.\\141There should be one-- and preferably only one --obvious way to do it.\\142Although that way may not be obvious at first unless you're Dutch.\\143Now is better than never.\\144Although never is often better than *right* now.\\145If the implementation is hard to explain, it's a bad idea.\\146If the implementation is easy to explain, it may be a good idea.\\147Namespaces are one honking great idea -- let's do more of those!148\end{frame}149150151\begin{frame}{commit messages}152\begin{columns}153\begin{column}{0.5\textwidth}154\begin{itemize}[<+->]155\item Can I understand what the commit was about?156\item Use prefixes157\item Mention issues158\end{itemize}159\end{column}160\begin{column}{0.5\textwidth}161\only<1>{cleanup, fixed bug, new feature, \dots}162\only<2>{163164\begin{itemize}165\item BUG: bug fix166\item DEV: development tool or utility167\item DOC: documentation168\item ENH: Enhancement, a new feature169\item MAINT: Maintenance task170\item REL: release171\item STY: Stylistic change172\item TST: addition or modification of tests173\end{itemize}174175Source: \href{https://docs.scipy.org/doc/numpy-1.13.0/dev/gitwash/development_workflow.html}{Scipy Docs}176}177\only<3>{178\begin{itemize}179\item See issue \#123180\item Closes issue \#123181\end{itemize}182}183\end{column}184\end{columns}185\end{frame}186187188\begin{frame}{commit ammend}189\texttt{\$ git commit --amend}190191\begin{itemize}192\item Add to last commit / change message193\item Only on feature branch as it might require force-push!194\end{itemize}195\end{frame}196197198\begin{frame}{commit squashing}199\begin{columns}200\begin{column}{0.5\textwidth}201\textbf{Commit squashing}202203Making multiple commits in a row become one204\end{column}205\begin{column}{0.5\textwidth}206\includegraphics[height=0.5\textheight]{graphics/commit-squashing.png}207{\small Image source: \href{https://stevenschwenke.de/GitToSquashOrNotToSquash}{stevenschwenke.de}}208\end{column}209\end{columns}210\end{frame}211212\begin{frame}{git merge}213\includegraphics[width=1.0\textwidth,height=0.5\textheight,keepaspectratio]{graphics/git-merge.png}214\end{frame}215216\begin{frame}{git merge vs git rebase}217\includegraphics[width=1.0\textwidth,height=0.8\textheight,keepaspectratio]{graphics/git-rebase.png}218219{\small Image source: \href{https://jeffkreeftmeijer.com/git-rebase/}{Jeff Kreeftmeijer}}220\end{frame}221222223\section{Bugs}224\begin{frame}{Logic Bugs: Functions and McCabe}225\inputminted[linenos,226numbersep=7pt,227fontsize=\footnotesize, tabsize=4]{python}{src/sieve-v1.py}228\end{frame}229230\begin{frame}{Logic Bugs: Names}231\inputminted[linenos,232numbersep=7pt,233fontsize=\footnotesize, tabsize=4,234firstline=4]{python}{src/sieve-v2.py}235\end{frame}236237\begin{frame}{Logic Bugs: Doctests!}238\inputminted[linenos,239numbersep=7pt,240fontsize=\footnotesize, tabsize=4,241firstline=8, lastline=24]{python}{src/sieve-v3.py}242\end{frame}243244245\section{Falsehood Data Scientists Beliefes}246\begin{frame}{Falsehood Data Scientists Beliefes}247\begin{centering}248(1) Floating point numbers always look like this: 1.23456 or 0.000004577 or 12345.467765.249\end{centering}250251\uncover<2->{252\begin{itemize}253\item<2-> Scientific notation: \texttt{4.577E-5} or \texttt{1.2345467765E4}254\item<3-> German decimal format: \texttt{1,23456} or \texttt{0,000004577}255\end{itemize}256}257\end{frame}258259\begin{frame}{Falsehood Data Scientists Beliefes}260\begin{centering}261(2.1) Country names have an unique representation262\end{centering}263264\uncover<2>{265\enquote{Germany} vs \enquote{Deutschland}266}267\end{frame}268269\begin{frame}{Falsehood Data Scientists Beliefes}270\begin{centering}271(2.2) Country names have an unique representation in English272\end{centering}273274\uncover<2>{275\enquote{United Kingdom} vs \enquote{UK}276}277\end{frame}278279\begin{frame}{Falsehood Data Scientists Beliefes}280\begin{centering}281(2.3) Country names have an unique unabreviated representation in English282\end{centering}283284\uncover<2>{285\enquote{United Kingdom} vs \enquote{Great Britain} vs \enquote{England}286}287\uncover<3>{Solution: Use/Demand \textbf{ISO 3166-1 alpha-3 country codes} everywhere}288\end{frame}289290\begin{frame}{Falsehood Data Scientists Beliefes}291\begin{centering}292(3) Data is clean293\end{centering}294295\uncover<2->{296No.297\begin{itemize}298\item<3-> User database: Birth date in the year 3.299\item<4-> User database: Active user who is more than 90 years old.300\item<5-> User database: User who is younger than 6.301\end{itemize}302}303\end{frame}304305\begin{frame}{Falsehood Data Scientists Beliefes}306\begin{centering}307(4) Time has no beginning and no end308\end{centering}309310\uncover<2->{311Unix Time Stamp: Seconds since 1st of January, 1970. Stored in unsigned int.312}313\end{frame}314315\begin{frame}{Falsehood Data Scientists Beliefes}316\begin{centering}317(4) To avoid the Year-2038 problem, I can store \texttt{YYYY-mm-dd HH:MM:ss}318\end{centering}319320\uncover<2->{321\begin{itemize}322\item<2-> \href{http://strftime.org/}{Python's strftime directives}323\item<3-> Timezones324\item<4-> Whenever possible, store the timezone and use \textbf{ISO 8601}:325\texttt{2012-04-23T18:25:43.511+02:30} (\href{https://stackoverflow.com/a/15952652/562769}{reasons})326\end{itemize}327}328\end{frame}329330331\begin{frame}{Falsehood Data Scientists Beliefes}332\begin{centering}333(5) The (physical) unit of a column / an API can be guessed.334\end{centering}335336\uncover<2->{337\begin{itemize}338\item<2-> Clarify it339\item<3-> See if the distribution / quantiles are reasonable340\item<4-> Internally, use unit library \href{http://pint.readthedocs.io/en/latest/}{Pint}341\end{itemize}342}343\end{frame}344345346\begin{frame}{See also}347\begin{itemize}348\item git349\begin{itemize}350\item \href{http://meldmerge.org/}{meld}: Tool for diff and merge (\texttt{\$ git mergetool})351\item \href{https://nvie.com/posts/a-successful-git-branching-model/}{A successful Git branching model}352\end{itemize}353\item \href{https://www.youtube.com/watch?v=8SNaW1nt6j0}{Debugging Python with ipdb and Sypder} - starting at 4:00354\item \href{https://docs.python.org/3/library/profile.html}{cprofile}: Check where code improvements are effective355\item David Goldberg: \href{https://www.itu.dk/~sestoft/bachelor/IEEE754_article.pdf}{What Every Computer Scientist Should Know About Floating-Point Arithmetic}356\item \href{https://martin-thoma.com/testing-python-code/}{Testing with Python}357\item \href{https://martin-thoma.com/logging-in-python/}{Logging with Python}358\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})359\item \href{https://balsamiq.com/}{Balsamiq}: Draft an UI360\item Web: \href{https://gist.github.com/alexserver/2fcc26f7e1ebcfc9f6d8}{REST basics}361\end{itemize}362\end{frame}363\end{document}364Bare excepts are only correct when trying to capture and forward exceptions - in all other cases, except Exception should be used to avoid catching KeyboardInterrupt.365366