\documentclass{beamer}
\mode<presentation>
{
%  \usetheme{AnnArbor}
%  \usetheme{Dresden}
%  \usetheme{Montpellier}
%  \usetheme{Antibes}
%  \usetheme{Frankfurt}
%  \usetheme{PaloAlto}
%  \usetheme{Bergen}
%  \usetheme{Goettingen}
%  \usetheme{Pittsburgh}	%!!
%  \usetheme{Berkeley}
%  \usetheme{Hannover}
%  \usetheme{Rochester}		%!!!
%  \usetheme{Berlin}
%  \usetheme{Ilmenau}
%  \usetheme{Singapore}
%  \usetheme{Boadilla}		%viel platz
%  \usetheme{JuanLesPins}
%  \usetheme{Szeged}		%!
%  \usetheme{boxes}
%  \usetheme{Luebeck}
%  \usetheme{Warsaw}
% \usetheme{Copenhagen}
  \usetheme{Madrid}
%  \usetheme{Darmstadt}
%  \usetheme{Malmoe}
%  \usetheme{default}
%  \usetheme{Marburg}

%  \setbeamercovered{transparent}
  % oder auch nicht

  %navigation aus, klaut nur platz
  %\setbeamertemplate{navigation symbols}{}
  \beamertemplatenavigationsymbolsempty  
}
\usepackage[latin1]{inputenc}
%\usepackage[german]{babel}
\usepackage{latexsym}
\usepackage{amsfonts}
%\usepackage{natbib}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{subfigure}
% oder was auch immer

\usepackage[latin1]{inputenc}
% oder was auch immer

\usepackage{times}
\usepackage[T1]{fontenc}
% Oder was auch immer. Zu beachten ist, das Font und Encoding passen
% müssen. Falls T1 nicht funktioniert, kann man versuchen, die Zeile
% mit fontenc zu löschen.

\usepackage{listings} 

\lstset{
language=Octave,                % choose the language of the code
tabsize=2,
frame=none, 
numbers=left, 
numberstyle=\tiny, 
numbersep=5pt,
stepnumber=2,
basicstyle=\tiny
}

\title[]% (optional, nur bei langen Titeln nötig)
{Beyond the Mouse -- A Short Course on Programming}

\subtitle
{1. Thinking programs}

\author[Ronni Grapenthin]% (optional, nur bei vielen Autoren)
{Ronni Grapenthin}
\institute[UAF/GI] % (optional, aber oft nötig)
{
Geophysical Institute, University of Alaska Fairbanks
}

% - Namen müssen in derselben Reihenfolge wie im Papier erscheinen.
% - Der \inst{?} Befehl sollte nur verwendet werden, wenn die Autoren
%   unterschiedlichen Instituten angehören.

% - Der \inst{?} Befehl sollte nur verwendet werden, wenn die Autoren
%   unterschiedlichen Instituten angehören.
% - Keep it simple, niemand interessiert sich für die genau Adresse.

\date[\today] % (optional, sollte der abgekürzte Konferenzname sein)
{\today}
% - Vollee oder abgekürzter Name sind möglich.
% - Dieser Eintrag ist nicht für das Publikum gedacht (das weiß
%   nämlich, bei welcher Konferenz es ist), sondern für Leute, die die
%   Folien später lesen.

\AtBeginSection[]
{
  \frame{
    \frametitle{Outline}
    \tableofcontents[currentsection,currentsubsection]
  }
}

% Falls Aufzählungen immer schrittweise gezeigt werden sollen, kann
% folgendes Kommando benutzt werden:

%\beamerdefaultoverlayspecification{<+->}

%\pgfdeclareimage[width=1.75cm,height=1.75cm]{logo_hu}{redoubt_images/pdc_cloud_2.pdf}
%\titlegraphic{\pgfuseimage{logo_hu}}

\setbeamertemplate{footline}[frame number]

\begin{document}

\frame{
	\begin{columns}[t]
	\column{0.5\textwidth}
		\titlepage
	\column{0.5\textwidth}
		\vspace{-0.3cm}
		\begin{center}
		\includegraphics[width=.75\textwidth]{../geoscience_programming/images/xkcd_2009_04_14_well_2_panel_2.pdf}
		\end{center}
		\begin{flushright}
			\tiny{``The Uncomfortable Truths Well'',\\ http://xkcd.com/568 (April 13, 2009)}
		\end{flushright}
	\end{columns}
}

\frame{
  \frametitle{Outline}
  \tableofcontents
}

\section[Overview and Philosophies]{Overview  and Philosophies}
\frame{
	\frametitle{The Program \dots}
		\begin{center}
		\includegraphics<1>[width=9cm]{program_schedule/schedule_01.pdf}
		\includegraphics<2>[width=9cm]{program_schedule/schedule_02.pdf}
		\includegraphics<3>[width=9cm]{program_schedule/schedule_03.pdf}
		\includegraphics<4>[width=9cm]{program_schedule/schedule_05.pdf}
		\includegraphics<5>[width=9cm]{program_schedule/schedule_06.pdf}
		\includegraphics<6>[width=9cm]{program_schedule/schedule_07.pdf}
		\includegraphics<7>[width=9cm]{program_schedule/schedule_08.pdf}
		\includegraphics<8>[width=9cm]{program_schedule/schedule_09.pdf}
		\includegraphics<9>[width=9cm]{program_schedule/schedule_problem.pdf}
		\end{center}
		\begin{flushright}
		{\tiny Listing 1: Class flow}
		\end{flushright}
}

\frame{
	\frametitle{Modules \dots (tentative order)}
		\begin{itemize}
			\item<1->{\tt brainWashing(), learnMantras()} -- {\bf Thinking Programs, Fundamentals of Programming }, me\\
				\emph{The esoteric / abstract side of programming.}
			\item<2->{\tt discoverWorld()} -- {\bf Unix Tools}, Jeff Freymueller, me\\
				\emph{Unix can make your life a lot easier. Intro to tools and scripting.}
			\item<3->{\tt drawMap()} -- {\bf Generic Mapping Tools}, Bernard Coakley\\
				\emph{GMT can map your data.}
			\item<4->{\tt newSpeak(), messWithData()} -- {\bf General Matlab}, Jeff Freymueller, me, TBD\\
				\emph{How to do atcual programming using Matlab. Things you can do to your data.}
			\item<5->{\tt webPresence(), stuffPlusPlus()} -- {\bf HTML/CSS, OO Overview}, me\\
				\emph{How does that homepage stuff work? Is that all I need to know?}
		\end{itemize}
}

\frame{
	\frametitle{Seminar materials}
		\begin{center}		
		{\tt http://www.gps.alaska.edu/programming}
		\end{center} 
		Things to find:\\
		\begin{itemize}
			\item slides: the actual presentation
			\item handouts: write up of lectures that should culminate in a manual type thing
			\item examples: working samples from each lecture.
			\item exercises: invitation for you.\\
		\end{itemize}
		Print slides before lecture so you can take necessary notes :)\\[20pt]
		This course is for you \dots give feedback! (any time, not just on the yellow sheets at the end)
}

\frame{
	\frametitle{The very basics (1)}
		\begin{block}{From `The Conscience of a Hacker', The Mentor (1986):}
		 [\dots] I made a discovery today.  I found a computer.  Wait a second, this is
		cool.  It does what I want it to.  If it makes a mistake, it's because I
		screwed it up.  Not because it doesn't like me \dots \\
                Or feels threatened by me \dots \\
                Or thinks I'm a smart ass \dots \\
                Or doesn't like teaching and shouldn't be here [\dots]
		\end{block}
}

\frame{
	\frametitle{The very basics (2)}
		\begin{block}{}
			\begin{itemize}			
			\item<1-> Programming is beyond language. 
			\item<2-> Programming is about writing code that people can read.
			\item<3-> Code is poetry.
			\item<4-> RTFM \emph{and/or} the internet
			\end{itemize}	
		\end{block}
		\begin{columns}[c]
			\column{6cm}
				\includegraphics[width=\textwidth]{../geoscience_programming/images/2b-or-not2b.jpg}\\
				\begin{flushright}
				{\tiny http://thinkgeek.com}
				\end{flushright}
			\column{6cm}
			\begin{quote}<3->
			``When I'm writing poetry, it feels like the center of my thinking is in a particular place, and when I'm writing code the center 				of my thinking feels in the same kind of place.''
			\begin{flushright}
			{\tiny Richard Gabriel,\\
			Distinguished Engineer at Sun Microsystems}
			\end{flushright}
			\end{quote}
		\end{columns}
}

\frame{
	\frametitle{More Philosophy \dots}
		\begin{block}{Jon Claerbout (a geophysicist), as quoted in ``WaveLab and Reproducible Research'':}
			~\\
			\begin{quotation}<2->
				\noindent An article about computational science in a scientific publication is {\bf not} the 
				scholarship itself, it is merely {\bf advertising} of the scholarship. The actual 
				scholarship is the complete software development environment and the complete set 
				of instructions which generated the figures.\\ 
			\end{quotation}
		\end{block}
		\begin{block}{Implications \dots}<3->
			\begin{itemize}			
			\item publications should include data and code (example: Okada)
			\item figures should be reproducible by readers
			\item write code that others can use!
			\end{itemize}			
		\end{block}
	}

\frame{
	\frametitle{What does that mean?}
	\begin{block}{Good}
		\begin{columns}[T]
		\column{0.75cm} ~
		\column{12cm}
		\lstinputlisting{../geoscience_programming/listings/screw2d.m}
		\end{columns}
	\end{block}
}

\frame{
	\frametitle{What does that mean?}
	\begin{block}{Bad}
		\begin{columns}[T]
		\column{0.75cm} ~
		\column{12cm}
		\lstinputlisting{../geoscience_programming/listings/screw2d_bad.m}
		\end{columns}
	\end{block}
}

%\frame{
%	\frametitle{Definitions}
%	\begin{block}{``Algorithm''}
%		\emph{recipe, process, method, techique, procedure, routine}
%		\begin{itemize}
%			\item finiteness
%			\item definiteness
%			\item input
%			\item output
%			\item effectiveness
%		\end{itemize}
%	\end{block}
%
%	\begin{block}{``Program''}
%		\emph{Piece of text that is valid according to the rules (syntax and grammar) of a programming language.}
%	\end{block}
%}


\section[Thinking]{Thinking programs}

\frame{
	\frametitle{Thinking programs -- Breaking down complex tasks}
	\begin{block}{Example 1:}
	\begin{center}	
		\Huge{Getting into Grad School}
	\end{center}
	\end{block}
	\begin{block}{things to do:}<2>
	\begin{center}	
		apply, figure out where to go, visa stuff, class work, research, thesis \dots
	\end{center}
	\end{block}
}

\frame{
	\frametitle{Thinking programs -- Breaking down complex tasks}
		\begin{center}
		\includegraphics<1>[width=6cm]{../geoscience_programming/program_grad_school/grad_school_01.pdf}
		\includegraphics<2>[width=6cm]{../geoscience_programming/program_grad_school/grad_school_02.pdf}
		\includegraphics<3>[width=6cm]{../geoscience_programming/program_grad_school/grad_school_03.pdf}
		\includegraphics<4>[width=6cm]{../geoscience_programming/program_grad_school/grad_school_04.pdf}
		\includegraphics<5>[width=6cm]{../geoscience_programming/program_grad_school/grad_school_05.pdf}
		\includegraphics<6>[width=6cm]{../geoscience_programming/program_grad_school/grad_school_06.pdf}
		\includegraphics<7>[width=6cm]{../geoscience_programming/program_grad_school/grad_school_07.pdf}
		\includegraphics<8>[width=6cm]{../geoscience_programming/program_grad_school/grad_school_08.pdf}
		\includegraphics<9>[width=6cm]{../geoscience_programming/program_grad_school/grad_school_09.pdf}
		\includegraphics<10>[width=6cm]{../geoscience_programming/program_grad_school/grad_school_10.pdf}
		\includegraphics<11>[width=6cm]{../geoscience_programming/program_grad_school/grad_school_11.pdf}
		\end{center}
		\begin{flushright}
		{\tiny Listing 1: Seminar flow}
		\end{flushright}
}

\frame{
	\frametitle{Thinking programs -- Breaking down complex tasks}
	\begin{block}{Example 2:}
	\begin{center}	
		\Huge{Grad student's Average Day}
	\end{center}
	\end{block}
	\begin{block}{possible activities:}<2>
	\begin{center}	
		eat, sleep, work, do stuff, \dots
	\end{center}
	\end{block}
}


\frame{
	\frametitle{Thinking programs -- Breaking down complex tasks}
		\begin{columns}
		\column{5cm}
			\begin{center}
			\includegraphics<1->[width=2.5cm]{../geoscience_programming/program_make_day/make_my_day.pdf}
			\end{center}
			\begin{flushright}
			{\tiny Listing 1: make\_my\_day}
			\end{flushright}
		\column{7cm}
			\begin{block}{possible implementation}<2>
				\begin{columns}[T]
				\column{0.75cm} ~
				\column{12cm}
					\lstinputlisting{../geoscience_programming/listings/make_my_day.m}
				\end{columns}
			\end{block}
		\end{columns}
			
}

\section[Building]{Building programs}
\frame{
	\frametitle{Building programs -- One black box at a time}
	Strategies to implement a program:
	\begin{columns}[T]
		\column{5.5cm}
		\begin{block}{Top down}<1->
			Same as the examples above:\\
			\begin{itemize}
				\item start with the big picture
				\item identify reasonable subtasks
				\item try to divide things to a level of managable complexity (atoms)
				\item implement atoms
				\item implement main routine (flow control)
			\end{itemize}
		\end{block}
		\column{1cm}
			~
		\column{5.5cm}
		\begin{block}{Bottom up}<2>
			\begin{itemize}
				\item problems accumulate
				\item implement an atom at the time
				\item at some point you figure out that things could go together
				\item revise main routine constantly
				\item add necessary subroutines
			\end{itemize}
		\end{block}
	\end{columns}
}

\frame{
	\frametitle{Building programs -- One black box at a time}
	\begin{block}{Bottom line}<1>
		\begin{itemize}
			\item Try building tools that solve a set of similar problems in a generic way. Use Parameters!
			\item Build and test each atom individually, test all scenarios (and more) with synthetic input.
			\item Treat atoms as black boxes that implement desired functionality. Don't care about them once they're working
		\end{itemize}
	\end{block}
}

\frame{
	\frametitle{Building programs -- One black box at a time}
	\begin{block}{Keys to good programs}
		\begin{itemize}
			\item<1-> {\bf Modularity}: split problem in manageable tasks, implement and test one at a time
			\item<2-> {\bf Reusability}: write functions, avoid redundance, avoid monolithic code (theoretically one loop would be enough)
			\begin{center}
			\includegraphics<2->[width=.75\textwidth]{../geoscience_programming/images/reuse_spectrum.pdf}
			\end{center}
			\begin{flushright}
			{\tiny Pidd, 2002}
			\end{flushright}
			\item<3-> {\bf Generalize}: use variables instead of hard coded values, hand parameters to functions
			\item<4-> Functionality, then efficiency
		\end{itemize}
	\end{block}
}

\frame{
	\frametitle{Building programs}
	\begin{columns}[T]
	\column{5.5cm}
		\begin{block}{The Control Routine}
			\begin{columns}[T]
			\column{0.75cm} ~
			\column{\textwidth}
			\lstinputlisting{../geoscience_programming/listings/make_my_day.m}
			\end{columns}
		\end{block}
		\column{5.5cm}
		\begin{block}{Using Parameters}
			\begin{columns}[T]
			\column{0.75cm} ~
			\column{\textwidth}
			\lstinputlisting{../geoscience_programming/listings/eat.m}
			\end{columns}
		\end{block}
	\end{columns}	
}

\section[Summary]{Summary}
\frame{
	\frametitle{Summary -- Take home messages}
	\begin{block}{Thinking \dots}<1->
		\begin{itemize}
			\item Think modular
			\item Think in general cases
			\item Think non-redundant
			\item Think about reuse
			\item Think about reproducibility
		\end{itemize}
	\end{block}

	\begin{block}{Exercising \dots}<1->
		\begin{itemize}
			\item Read other peoples' code \dots critically
			\item The first version is for the trash bin (unintentionally)
		\end{itemize}
	\end{block}
}

\frame{
	\frametitle{If all fails \dots}
		\begin{center}
		\includegraphics[width=.75\textwidth]{../geoscience_programming/images/xkcd_ballmer_peak.jpg}
		\end{center}
		\begin{flushright}
		{\tiny ``The Ballmer Peak'' \\http://www.xkcd.com/323/}
		\end{flushright}
}



\end{document}
