

% add the PATH to retrieve cls and sty beamer styles files
\makeatletter
\providecommand*{\input@path}{}
\edef\input@path{{../../support/beamer/}\input@path}% prepend
\makeatother

% \documentclass{pharoslides}
% \documentclass[aspectratio=169]{pharoslides} % format 16/9
\documentclass[withvideo]{pharoslides} % format 16/9 + incrustation video

\graphicspath{{./figures/}{../}{../../support/beamer/imgs/}}

%Information to be included in the title page:
\title{Variables}
\subtitle{}
\author{Damien Cassou, Stéphane Ducasse and Luc Fabresse}
\institute{http://stephane.ducasse.free.fr}
\date{}
\slidesid{W3S03}

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{In a Nutshell}

\begin{itemize}
\item \textbf{Local} variables start with \textbf{lowercase} (temps, instance variables, arguments,...)
\item \textbf{Shared} variables start with \textbf{uppercase} (class, class variables)
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Local Variables Start With Lowercase}

\textbf{Temporary variables} are local to the method

Example: \code{c}

\begin{listing}{}
CounterTest >> testIncrement
   | c |
   c := Counter new.
   ...
\end{listing}

Remember: class names start with uppercase
\end{frame}



\begin{frame}[fragile]

\frametitle{Local Variables Start With Lowercase}

\textbf{Instance variables} are local to the object

Example: \code{x}, \code{y}, \code{count}

\begin{listing}{}
Object subclass: #Point
   instanceVarNames: 'x y'
\end{listing}

\begin{listing}{}
Object subclass: #Counter
   instanceVarNames: 'count'
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Local Variables Start With Lowercase}

\textbf{Method arguments}: \code{aPoint}

\begin{listing}{}
crossProduct: aPoint 
  "Answer a number that is the cross product of the receiver and the 
  argument, aPoint."

  ^ (x * aPoint y) - (y * aPoint x)
\end{listing}

\textbf{Block arguments}: \code{:x}

\begin{listing}{}
[ :x | x + 2 ]
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Special Variables}

Special variables cannot be changed

\begin{itemize}
\item \code{true}, \code{false}, \code{nil}
\item \code{self}, \code{super}, \code{thisContext}
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Special Variables}

\begin{itemize}
\item \code{true}, \code{false} are the Booleans
\begin{itemize}
\item \code{true} is the unique instance of the class \code{True}
\item \code{false} is the unique instance of the class \code{False}
\end{itemize}

\item \code{nil} is the unique instance of the class \code{UndefinedObject} 
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Special Variables}

\begin{itemize}
\item \code{self} refers to the receiver of the message (\code{this} in Java)
\item \code{super} refers to the receiver but the method lookup starts in the superclass of the class defining the method (see dedicated Lectures)
\item \code{thisContext} refers to the current execution stack (advanced)
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Shared or Global Variable starts with Uppercase}

\code{Object} is a class globally accessible

\begin{listing}{}
Object subclass: #Point
\end{listing}

\code{Transcript} is an object that is globally accessible (a kind of stdout)

\begin{listing}{}
Transcript cr.
Transcript show: 'hello world'.
Transcript cr.
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{ClassVariables are Shared Variables}

\begin{itemize}
\item To share information between all the instances of a class and subclasses
\item Use a classVariable
\end{itemize}

\begin{listing}{}
Object subclass: #CombinedChar
   instanceVariableNames: 'codes combined'
   classVariableNames: 'Compositions Decompositions Diacriticals'
   package: 'Kernel-BasicObjects'
\end{listing}

\begin{itemize}
\item Here \code{Compositions} is shared between all the \code{CombinedChar} instances and instances of subclasses
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Summary}

\begin{itemize}
\item Lowercase are used for local/private/temporary variables
\item Uppercase are used for shared or global variables
\end{itemize}
\end{frame}




% \setlength{\textwidth}{\originaltextwidth}
\setbeamertemplate{background canvas}{\insertBorderForHandout}

\begin{frame}[plain]

\begin{minipage}{\originaltextwidth}
\centering
\large


\vspace{2em}

A course by

\vspace{1em}

\hspace{-20px}\includegraphics[height=32px]{inriaLogo}\hspace{3em}\raisebox{7px}{and}\hspace{3em}\raisebox{-6px}{\includegraphics[height=30px]{logoutop}}

\vspace{2em}

in collaboration with

\vspace{1em}

\includegraphics[height=40px]{unisciellogo}\hskip 1.5em%
\raisebox{5px}{\includegraphics[height=30px]{unitlogo}}\hskip 2em%
\raisebox{8px}{\includegraphics[height=24px]{univLilleLogo}}\hskip 2em%
\raisebox{3px}{\includegraphics[height=29px]{logo-IMT}}\hskip 2em%
\raisebox{1px}{\includegraphics[height=32px]{minesDouaiLogo}}

\vspace{2.5em}

\includegraphics[width=50px]{by-nc-nd} \tiny \hskip 0.5em \raisebox{5px}{Inria 2016}

\medskip

\tiny
Except where otherwise noted, this work is licensed under CC BY-NC-ND 3.0 France

\url{https://creativecommons.org/licenses/by-nc-nd/3.0/fr/} 

\end{minipage}
\end{frame}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
