Commit e162ebfc authored by Laros's avatar Laros
Browse files

Made the programming lecture compilable.

parent 962ad651
% LUMC presentation template by J. F. J. Laros.
% Last alteration on 20-02-2011.
%
% The packages texlive-latex-recommended, texlive-latex-base and
% texlive-latex-extra should be installed.
%
% Alter these four lines for a new presentation.
\providecommand{\me}{Jeroen F. J. Laros}
\providecommand{\myTitle}{Good Practices for Programming}
\documentclass[slidestop]{beamer}
\title{Good Practices for Programming}
\providecommand{\myConference}{Bioinformatics Work discussion}
\providecommand{\myDate}{Tuesday, 1 February 2011}
% Now go to %%% BEGIN PRESENTATION %%%
\documentclass[a4, portrait]{seminar}
\usepackage{semcolor} % For coloured text.
\usepackage{slidesec} % For section headings.
\usepackage{newcent} % This is a better font for presentations.
\usepackage{listings}
\input{seminar.bug}
\usepackage{graphicx} % For pictures.
\usepackage{fancybox} % For the background picture.
\usepackage[labelfont={color=white}, textfont={color=white}]{caption}
\definecolor{Blue}{rgb}{0.,0.11372,0.37647} % Custom LUMC color
\renewcommand{\labelitemi}{\textcolor{white}{$\bullet$}} % Make the bullets for
\renewcommand{\labelitemii}{\textcolor{white}{--}} % itemising white.
\renewcommand{\labelitemiii}{\textcolor{white}{$\ast$}}
\renewcommand{\labelitemiv}{\textcolor{white}{$\circ$}}
\renewcommand{\labelenumi}{\textcolor{white}{\arabic{enumi}.}}
\newslideframe{TITLE}{ % Template for the title.
\boxput{
\rput(0, 0){\includegraphics[angle=90, scale=.485]{bg}}
}{#1}
}
\newslideframe{PRES}{ % Template for the body.
\boxput{
\rput(0, 0){\includegraphics[angle=90, scale=.485]{bg2}}
}{
\textcolor{Blue}{
\rput[l]{90}(8.57, -1.5){\scriptsize{\myConference}}
\rput[c]{90}(8.57, 5.35){\scriptsize{\theslide/\pageref{LastPage}}}
\rput[r]{90}(8.57, 12.2){\scriptsize{\myDate}}
}
\white #1
\author{Jeroen F. J. Laros}
\providecommand{\myGroup}{Leiden Genome Technology Center}
\providecommand{\myDepartment}{Department of Human Genetics}
\providecommand{\myCenter}{Center for Human and Clinical Genetics}
\providecommand{\lastCenterLogo}{
\raisebox{-0.1cm}{
\includegraphics[height = 1cm]{lgtc_logo}
%\includegraphics[height = 0.7cm]{ngi_logo}
}
}
\renewcommand{\makeslideheading}[1]{ % Put the slide headings on top.
\rput[l](0.2, .40){
\textbf{
\textcolor{Blue}{#1}
}
}
\newline
\providecommand{\lastRightLogo}{
\includegraphics[height = 0.7cm]{nbic_logo}
%\includegraphics[height = 0.8cm]{nwo_logo_en}
%\hspace{1.5cm}\includegraphics[height = 0.7cm]{gen2phen_logo}
}
\pagestyle{empty}
\usetheme{lumc}
\begin{document}
\slideframe{TITLE} % Use the title template.
\begin{slide}
\setcounter{slide}{0}
\vspace*{1.5cm}
\begin{center}
{\bf\Large{\myTitle}}\\
\vfill
\textcolor{Blue}{
{\bf
\small{\me}\\
\small{Leiden Genome Technology Center}\\
\small{Department of Human Genetics}\\
\small{Center for Human and Clinical Genetics}
}
}
\vspace{1.1cm}
\end{center}
\end{slide}
\slideframe{PRES} % Use the body template.
%%% BEGIN PRESENTATION %%%
\lstset{
language = Python,
basicstyle = \footnotesize,
lineskip = -0.5ex,
frame = shadowbox,
rulesepcolor = \color{black},
captionpos = b,
numbers = left,
numbersep = -1em,
numberstyle = \tiny
}
% This disables the \pause command, handy in the editing phase.
%\renewcommand{\pause}{}
\begin{slide}
\slideheading{Introduction}
% Make the title page.
\bodytemplate
% First page of the presentation.
\section{Introduction}
\begin{pframe}
A very short and incomplete introduction to good practices for programming.
\bigskip
......@@ -120,11 +48,9 @@
We will try to show the use and advantages of some standard practices by
giving examples.
\vfill
\end{slide}
\begin{slide}
\slideheading{Introduction}
\end{pframe}
\begin{pframe}
We shall \emph{not} cover software development as a whole:
\bigskip
......@@ -139,11 +65,9 @@
We focus on basic programming.
\vfill
\end{slide}
\begin{slide}
\slideheading{Introduction}
\end{pframe}
\begin{pframe}
We \emph{will} focus on:
\bigskip
......@@ -162,11 +86,10 @@
\item Unit tests.
\end{itemize}
\vfill
\end{slide}
\begin{slide}
\slideheading{Indentation}
\end{pframe}
\section{Indentation}
\begin{pframe}
Indentation is a way to reveal the control flow of a program.
\bigskip
......@@ -184,11 +107,9 @@
Line $4$ is in the scope of the \lstinline!if!-clause.
\vfill
\end{slide}
\begin{slide}
\slideheading{Indentation}
\end{pframe}
\begin{pframe}
A piece of C code without indentation.
\bigskip
......@@ -206,11 +127,9 @@
C (unlike Python) does not \emph{require} indentation.
\vfill
\end{slide}
\begin{slide}
\slideheading{Indentation}
\end{pframe}
\begin{pframe}
A piece of C code without indentation.
\bigskip
......@@ -228,15 +147,13 @@
Notice the small change: the \lstinline!{! from line $2$ is now on line $1$.
\vfill
\end{slide}
\begin{slide}
\slideheading{Indentation}
\end{pframe}
\begin{pframe}
Use indentation to reveal the control flow of the code.
\bigskip
\begin{lstlisting}[language = C, caption = {Same code as in Listing~\ref{u1}}]
\begin{lstlisting}[language = C, caption = {Same code as in Listing~\protect\ref{u1}}]
for (i = 0; i < 10; i++)
for (j = 0; j < 20; j++) {
if (i == j)
......@@ -251,15 +168,13 @@
All \lstinline!if! statements are in the scope of the inner
\lstinline!for!-loop.
\vfill
\end{slide}
\begin{slide}
\slideheading{Indentation}
\end{pframe}
\begin{pframe}
Notice the same small change, it is easier to spot.
\bigskip
\begin{lstlisting}[language = C, caption = {Same code as in Listing~\ref{u2}}]
\begin{lstlisting}[language = C, caption = {Same code as in Listing~\protect\ref{u2}}]
for (i = 0; i < 10; i++) {
for (j = 0; j < 20; j++)
if (i == j)
......@@ -274,11 +189,10 @@
Only the first \lstinline!if! statement is in the scope of the inner
\lstinline!for!-loop.
\vfill
\end{slide}
\begin{slide}
\slideheading{Functions}
\end{pframe}
\section{Functions}
\begin{pframe}
Functions (procedures, methods, subroutines) are used for:
\bigskip
......@@ -291,11 +205,9 @@
In general, try to use functions as much as possible
\vfill
\end{slide}
\begin{slide}
\slideheading{Functions}
\end{pframe}
\begin{pframe}
A piece of sample code (with an intentional flaw).
\bigskip
......@@ -317,11 +229,9 @@
d4 = c1 + c2 / 2
\end{lstlisting}
\vfill
\end{slide}
\begin{slide}
\slideheading{Functions}
\end{pframe}
\begin{pframe}
Writing comment often helps to identify code duplication.
\bigskip
......@@ -343,15 +253,13 @@
d3 = c1 + c2 / 2
\end{lstlisting}
\vfill
\end{slide}
\begin{slide}
\slideheading{Functions}
\end{pframe}
\begin{pframe}
Use functions to avoid code duplication.
\bigskip
\begin{lstlisting}[caption = {Same functionality as in Listing~\ref{f2}},
\begin{lstlisting}[caption = {Same functionality as in Listing~\protect\ref{f2}},
label = f3]
def f(a, b) :
c1 = a * a # c1 is a1^2
......@@ -368,11 +276,9 @@
It is now trivial to add more calls to this function.
\vfill
\end{slide}
\begin{slide}
\slideheading{Functions}
\end{pframe}
\begin{pframe}
Functions also makes altering code easier.
\bigskip
......@@ -393,11 +299,9 @@
Altering the same behaviour in the flat code would be time consuming and
prone to errors.
\vfill
\end{slide}
\begin{slide}
\slideheading{Functions}
\end{pframe}
\begin{pframe}
Use meaningful names for functions and variables.
\bigskip
......@@ -407,7 +311,7 @@
\end{lstlisting}
\bigskip
\begin{lstlisting}[caption = {Same functionality as Listing~\ref{m1}},
\begin{lstlisting}[caption = {Same functionality as Listing~\protect\ref{m1}},
numbers = none]
insertSize = 2 * readLength + internalSize
\end{lstlisting}
......@@ -415,16 +319,14 @@
Names should reflect the function.
\vfill
\end{slide}
\end{pframe}
\begin{slide}
\slideheading{Functions}
\begin{pframe}
Use meaningful names for functions and variables.
\bigskip
\begin{lstlisting}[caption = {Same functionality as Listing~\ref{f3}}]
\begin{lstlisting}[caption = {Same functionality as Listing~\protect\ref{f3}}]
def meanOfSquares(a, b) :
aSquare = a * a
bSquare = b * b
......@@ -440,11 +342,9 @@
Notice that inline comment is no longer needed (in this case).
\vfill
\end{slide}
\begin{slide}
\slideheading{Functions}
\end{pframe}
\begin{pframe}
Document each function.
\bigskip
......@@ -468,11 +368,9 @@
#meanOfSquares
\end{lstlisting}
\vfill
\end{slide}
\begin{slide}
\slideheading{Functions}
\end{pframe}
\begin{pframe}
Alternative documentation.
\begin{lstlisting}[caption = {Documentation with a markup language},
label = f4]
......@@ -496,15 +394,14 @@
#meanOfSquares
\end{lstlisting}
\vfill
\end{slide}
\begin{slide}
\slideheading{Unit tests}
\end{pframe}
\section{Unit tests}
\begin{pframe}
Test the implementation of a function.
\bigskip
\begin{lstlisting}[caption = {Unit test of Listing~\ref{f4}}]
\begin{lstlisting}[caption = {Unit test of Listing~\protect\ref{f4}}]
def testMeanOfSquares() :
"""
Test the meanOfSquares() function.
......@@ -518,11 +415,9 @@
This function will report an error because of a flaw in the function.
\vfill
\end{slide}
\begin{slide}
\slideheading{Functions}
\end{pframe}
\begin{pframe}
Because of the unit test, we identified the flaw.
\begin{lstlisting}[caption = {Final function}]
......@@ -546,14 +441,11 @@
#meanOfSquares
\end{lstlisting}
\vfill
\end{slide}
\end{pframe}
\begin{slide}
\rput(5.4,0.7){\includegraphics[scale=0.07]{lgtc_logo}}
\rput(10.6,0.6){\includegraphics[scale=0.1]{nbic_logo}}
\slideheading{Questions?}
\label{LastPage}
\vfill
\end{slide}
\section{Questions?}
\lastpagetemplate
\begin{frame}
\end{frame}
\end{document}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment