

% 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{Messages for Java Programmers}
\subtitle{}
\author{Damien Cassou, Stéphane Ducasse and Luc Fabresse}
\institute{http://stephane.ducasse.free.fr}
\date{}
\slidesid{W2S02}

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{Only Objects and Messages}

\begin{itemize}
\item code in Pharo \textbf{only} manipulates objects: mouse, booleans, arrays, numbers, compressed, strings, windows, scrollbars, canvas, files, trees, compiler, sound, url, socket, fonts, text, collections, stack, shortcut, streams, ...
\item messages and assignments are the only way to do something
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Equivalence}

In Java

\begin{listing}{}
    ArrayList<String> strings = new ArrayList<String>();
\end{listing}

In Pharo

\begin{listing}{}
strings := OrderedCollection new.
\end{listing}

\begin{itemize}
\item 1 assignment, 1 message sent
\item \code{new} is a message sent to a class
\item no static typing
\item no generics
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Equivalence}

In Java

\begin{listing}{}
Thread regThread = new Thread(
  new Runnable() {
    @Override
    public void run() {
      this.doSomething();
    }
  });
regThread.start();
\end{listing}

In Pharo

\begin{listing}{}
[ self doSomething ] fork
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Equivalence}

In Java 8

\begin{listing}{}
new Thread(() -> this.doSomething()).start();
\end{listing}

In Pharo

\begin{listing}{}
[ self doSomething ] fork
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Three Kinds of Messages}

\begin{itemize}
\item Unary
\end{itemize}

\begin{listing}{}
5 factorial
Transcript cr
\end{listing}

\begin{itemize}
\item Binary
\end{itemize}

\begin{listing}{}
3 + 4
5 -> 10
\end{listing}

\begin{itemize}
\item Keyword-based
\end{itemize}

\begin{listing}{}
Transcript show: 'hello world'
2 between: 0 and: 5
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Keyword Messages for Java developers}

In Java

\begin{listing}{}
    receiver.keyword1keyword2(arg1, arg2)
\end{listing}

In Pharo

\begin{listing}{}
    anObject keyword1: arg1 keyword2: arg2
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Keyword Messages for Java developers}

In Java

\begin{listing}{}
    postman.send(mail,recipient);
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Keyword Messages for Java developers}

\begin{listing}{}
    postman.send(mail,recipient);
    postman . send ( mail , recipient );
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Keyword Messages for Java developers}

\begin{listing}{}
    postman.send(mail,recipient);
    postman . send ( mail , recipient );
    postman send mail recipient
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Keyword Messages for Java developers}

\begin{listing}{}
    postman.send(mail,recipient);
    postman . send ( mail , recipient );
    postman send mail recipient
    postman send mail to recipient
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Keyword Messages for Java developers}

\begin{listing}{}
    postman.send(mail,recipient);
    postman . send ( mail , recipient );
    postman send mail recipient
    postman send mail to recipient
    postman send: mail to: recipient
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Keyword Messages for Java developers}

In Java

\begin{listing}{}
    postman.send(mail,recipient);
\end{listing}

In Pharo

\begin{listing}{}
    postman send: mail to: recipient
\end{listing}

\begin{itemize}
\item the message
\begin{itemize}
\item is named \code{send:to:}
\item is sent to \code{postman}
\item includes two arguments (\code{mail} and \code{recipient})
\end{itemize}

\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Conditionals are Just Messages}

\begin{itemize}
\item in Java, \code{if}, \code{else}, \code{for}, \code{while}, \code{do}, ... are language keywords
\item in Pharo, conditional expressions are messages
\item booleans are objects
\end{itemize}

\begin{listing}{}
fullName isEmpty
   ifTrue: [ 'FirstnameLastname' ]
   ifFalse: [ fullName ]
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Loops are Just Messages}

\begin{listing}{}
4 timesRepeat: [ self doSomething ]
\end{listing}

\begin{listing}{}
0 to: 100 do: [ :i | ... ]
\end{listing}

\begin{listing}{}
0 to: 100 by: 3 do: [ :i | ... ]
\end{listing}

\begin{listing}{}
aCollection do: [ :each | ... ]
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Summary}

\begin{itemize}
\item Three kinds of messages: unary, binary and keywords
\item () \textgreater{} unary \textgreater{} binary \textgreater{} keywords
\item Conditionals are messages
\item Loops too
\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:
