\documentclass[xcolor=usenames,dvipsnames,svgnames,table]{beamer}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,arrows,shapes,intersections}
%\usepackage{subcaption}
\usepackage{siunitx}
\usepackage{multimedia}
\usepackage{listings}
\lstset{aboveskip=10pt,belowskip=10pt,lineskip={-1.5pt}}

\usepackage{multirow}
\usepackage{graphicx}
\usepackage{hyperref}

\usepackage{standalone}
\usepackage{media9}
\usepackage{textcomp}
\usepackage{smartdiagram}
\usesmartdiagramlibrary{additions}

\newcommand{\todo}[1]{{\color{red}~TODO!~{#1} }}

\usetheme{Warsaw}

\beamertemplatenavigationsymbolsempty%
\setbeamertemplate{footline}[frame number]
\setbeamertemplate{itemize item}[triangle]


\date{Jan 21, 2019}
\title{Waves2Weather --- ECS Workshop}
\author[Z2]{Z2, Scientific Programmers at Your Service}

\begin{document}

\begin{frame}
\institute{%
	LMU --- Meteorological Institute Munich\\[\medskipamount]
	\includegraphics[width=.5\textwidth,height=.3\textheight]{title.jpg}%
}

\titlepage%
\end{frame}



\begin{frame}
Developing scientific code
\begin{itemize}
	\item write function
	\item print result and check for correctness
	\item check use cases, edge cases, invalid input
\end{itemize}
\visible<2->{%
\hrulefill\\%
adding tests to it \ldots
	\begin{itemize}
		\item record output and form automated tests
		\item check for physical constraints\,(i.e.\ analytic solutions, symmetries, conservation properties)
		\item if you find a bug, make a test out of it
	\end{itemize}
}
\end{frame}



\begin{frame}
\begin{block}{Runtime Assertions\,(defensive programming)}
    \begin{itemize}
		\item check status of input
		\item check intermediate values
		\item immediate exit simplifies debugging
		\item always return status and check it! \textrightarrow{} traceback
    \end{itemize}
\end{block}

\begin{block}{Testing buzzword bingo}
	\begin{itemize}
		\item unit tests --- single function
		\item integration tests --- combination of parts
		\item regression tests --- behaviour stays the same
		\item full system tests --- test full model
		\item test driven development
		\item automated testing \& continuous integration
	\end{itemize}
\end{block}
\end{frame}

\begin{frame}
\frametitle{Running tests automatically, Continous Integration}
\begin{columns}

	\column[c]{.45\textwidth}
	\includegraphics[width=\textwidth]{gitlabci.png}

	\column[c]{.55\textwidth}
	\smartdiagramset{%
		uniform color list=blue!40 for 5 items,
		circular final arrow disabled=true,
		back arrow disabled=true,
		circular distance=2.25cm,
		arrow tip=to,
		arrow line width=2pt,
		text width=11em
	}
	\smartdiagram[flow diagram]{%
		feature branch,
		run tests,
		push to gitlab,
		gitlab CI\\test multiple environments,
		merge request\\code review
	}
\end{columns}
\end{frame}


\input{../../slides/coding_tools_large_projects/slide}




\begin{frame}
\guillemotleft\ Best Practices for Scientific Computing \guillemotright{} \\%
{\vspace{-.3em} \tiny Wilson G et al.\,(2014) doi.org/10.1371/journal.pbio.1001745}

\,\\

\begin{itemize}
%		\only<1>{%
%		\item Write programs for people, not computers.
%			\begin{itemize}
%				\item A program should not require its readers to hold more than a handful of facts in memory at once.
%				\item Make names consistent, distinctive, and meaningful.
%				\item Make code style and formatting consistent.
%			\end{itemize}
%		}
		\only<1>{%
		\item Let the computer do the work.
			\begin{itemize}
				\item Make the computer repeat tasks.
				\item Save recent commands in a file for re-use.
				\item Use a build tool to automate workflows.\\{\it\bf (remember climate model setup)}
			\end{itemize}
		}
		\only<1>{%
		\item Make incremental changes.
			\begin{itemize}
				\item Work in small steps with frequent feedback and course correction.
				\item Use a version control system.
				\item Put everything that has been created manually in version control. {\it\bf (W2W data managment)}
			\end{itemize}
		}
%		\only<2>{%
%		\item Don't repeat yourself (or others).
%			\begin{itemize}
%				\item Every piece of data must have a single authoritative representation in the system.
%				\item Modularize code rather than copying and pasting.
%				\item Re-use code instead of rewriting it.
%			\end{itemize}
%		}
		\only<2>{%
		\item Plan for mistakes.
			\begin{itemize}
				\item Add assertions to programs to check their operation.
				\item Use an off-the-shelf unit testing library. {\it\bf (e.g.\ nosetest)}
				\item Turn bugs into test cases.
				\item Use a symbolic debugger.
			\end{itemize}
		}
%		\only<2>{%
%		\item Optimize software only after it works correctly.
%			\begin{itemize}
%				\item Use a profiler to identify bottlenecks.
%				\item Write code in the highest-level language possible.
%			\end{itemize}
%		}
%		\only<4>{%
%		\item Document design and purpose, not mechanics.
%			\begin{itemize}
%				\item Document interfaces and reasons, not implementations.
%				\item Refactor code in preference to explaining how it works.
%				\item Embed the documentation for a piece of software in that software.
%			\end{itemize}
%       }
		\only<2>{%
		\item Collaborate.
			\begin{itemize}
				\item Use pre-merge code reviews.
				\item Use pair programming when bringing someone new up to speed and when tackling particularly tricky problems.
				\item Use an issue tracking tool. {\it\bf (gitlab merge requests and CI)}
			\end{itemize}
		}
	\end{itemize}
\end{frame}

\end{document}
