

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

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{Behind the Scene}

\begin{itemize}
\item What is happening when we recompile a class?
\item What are the reflective operations that take place?
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{A Typical Scenario}

\begin{itemize}
\item Define one class
\item Define some methods
\item Create some instances
\item Add an instance variable to the class
\item Existing instances got mutated
\item Continue working
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Operations Supporting Interactive Coding}

\begin{itemize}
\item Dynamic class (re)definition
\item Method recompilation
\item Transparent instance migration
\begin{itemize}
\item Collecting instances
\item Switching pointers from old to new instances
\end{itemize}

\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Getting All Instances}

\begin{listing}{}
Dictionary allInstances size
\end{listing}

\begin{listing}{}
Window allInstances first close
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Getting All Pointers to an Object}

\begin{listing}{}
anObject pointersTo
\end{listing}

returns all objects that store a reference to \code{anObject}
\end{frame}



\begin{frame}[fragile]

\frametitle{Symmetric Pointer Swapping}

\begin{listing}{}
anObject become: anotherObject
\end{listing}

\begin{itemize}
\item All the pointers to \code{anObject} point now to \code{anotherObject} 
\item And \symbol{34}the inverse\symbol{34} atomically
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Symmetric Pointer Swapping}

\begin{listing}{}
| pt1 pt2 pt3 |
pt1 := 0@0.
pt2 := pt1.
pt3 := 100@100.
pt1 become: pt3.
self assert: pt2 = (100@100). 
self assert: pt3 = (0@0).
self assert: pt1 = (100@100)
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Asymmetric Pointer Swapping}

Swap all the pointers from one object to the other (asymmetric)

\begin{listing}{}
anObject becomeForward: anotherObject
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Example: Asymmetric Pointer Swapping}

\begin{listing}{}
| pt1 pt2 pt3 |
pt1 := 0@0.
pt2 := pt1.
pt3 := 100@100.
pt1 becomeForward: pt3.
self assert: pt1 = (100@100).
self assert: pt1 == pt2.
self assert: pt2 == pt3.
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Changing the Class of an Object}

\begin{listing}{}
Class >> adoptInstance: anInstance
   "Change the class of anInstance to me. Returns the class rather than the modified instance"
\end{listing}

\begin{itemize}
\item Limited reflective feature
\item Target class should have the same format as the original one
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Essence of a Class}

\begin{enumerate}
\item A format  i.e., a number of instance variables and types (named/indexed)
\item A superclass
\item A method dictionary
\end{enumerate}
\end{frame}



\begin{frame}[fragile]

\frametitle{Class initialize}

\begin{listing}{}
Behavior >> initialize

  super initialize.
  self superclass: Object.
  self methodDict: self emptyMethodDictionary.
  self setFormat: Object format.
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Instance Specific Behavior}

\begin{listing}{}
| behavior model newClass |
behavior := Behavior new.
behavior superclass: Model.
behavior setFormat: Model format.
model := Model new.
model primitiveChangeClassTo: behavior new. 
self assert: model class = behavior.
self assert: model class superclass = Model.
behavior compile: 'foo ^ 2'.
self assert: model foo = 2.
self should: [Model new foo] raise: MessageNotUnderstood
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Instance Specific Behavior}


\begin{center}
\includegraphics[width=1.0\textwidth]{figures/10AnonymousClasses.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{Anonymous Classes For Spying}

\begin{listing}{}
| logClass set | 
logClass := Behavior new. 
logClass superclass: Set;
   setFormat: Set format.
logClass compile: 'add: anObject
      Transcript show: ''adding '', anObject printString; cr.
      ^ super add: anObject'.
set := Set new.
set add: 1.
set class. 
set primitiveChangeClassTo: logClass basicNew. 
set add: 2.
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Conclusion}

\begin{itemize}
\item Reflection is a solid foundation for innovation and language extensibility
\item Avoid using reflective operations in domain code
\item Understand when you absolutely need reflection
\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:
