]> git.uio.no Git - ifi-stolz-refaktor.git/blobdiff - presentation/master-presentation-erlenkr.tex
now also works with blockless constructs (if, for, etc)
[ifi-stolz-refaktor.git] / presentation / master-presentation-erlenkr.tex
index 1f4117e00cac4858b3b9c48850d3cb8174061289..8cb92b2a04e8208a151128e8f8ce241bc9843a3b 100644 (file)
@@ -1,12 +1,10 @@
-% Motivate! (coupling)
-% Rework examples
 % Law of demeter?
 \documentclass[USenglish,9pt]{beamer}
 \usepackage[utf8]{inputenc}
 \usepackage[T1]{fontenc}
 \usepackage{lmodern}
 \usepackage{babel,textcomp}
-\usepackage[style=alphabetic,backend=biber]{biblatex}
+\usepackage[style=alphabetic,backend=biber,doi=false,isbn=false]{biblatex}
 \usepackage{babel,textcomp,csquotes}
 \usepackage{xspace}
 
 
 \begin{frame}
   \frametitle{Refactoring, as defined in the literature}
-  In his book on refactoring\citing{refactoring}, Martin Fowler defines a
-  refactoring like this:
 
   \begin{quote}
     \emph{Refactoring} (noun): a change made to the internal structure
 
 \begin{frame}
   \frametitle{An alternative definition of refactoring}
-  If we leave the motivation behind refactoring out of the definition, it could 
-  be rephrased like this:
 
   \begin{definition}
     A \emph{refactoring} is a transformation
 \end{frame}
 
 \begin{frame}
-  \frametitle{Composite refactorings}
-  \emph{Primitive refactorings} are refactorings that cannot be expressed in 
-  terms of other refactorings. From these, we can express \emph{composite
-  refactorings}:
+  \frametitle{Primitive and composite refactorings}
+  \begin{definition}
+    A \emph{primitive refactoring} is a refactoring that cannot be expressed in 
+    terms of other refactorings.
+
+  \end{definition}
 
   \begin{definition}
     A \emph{composite refactoring} is a refactoring that can be expressed in 
@@ -220,7 +216,8 @@ class Y {
   \begin{itemize}
     \item Get rid of long navigation paths.
     \item Move operations closer to the data they manipulate.
-    \item Eliminate coupling.
+    \item Reduce coupling.
+    \item Increase maintainability.
   
   \end{itemize}
 
@@ -230,10 +227,7 @@ class Y {
 
 \begin{frame}[fragile]
   \frametitle{The Extract Method refactoring}
-  The \refa{Extract Method} refactoring is used to extract a fragment of code 
-  out of its context and into a new method. A call to this new method is inlined 
-  where the fragment was before. The refactoring is used to break code into 
-  logical units, with names that explain their purpose.
+  Extract a fragment of code into a new method.
 
 \def\charwidth{4.5pt}
 \def\indent{2*\charwidth}
@@ -285,41 +279,12 @@ class C {
 \vfill
 \end{minipage}
 
-%  \begin{multicols}{2}
-%    \begin{minted}[samepage]{java}
-%  class C {
-%    void method() {
-%      // 1: Some code
-%      // 2: Fragment
-%      // 3: More code
-%    }
-%  }
-%    \end{minted}
-%
-%    \columnbreak
-%
-%    \begin{minted}[samepage]{java}
-%  class C {
-%    void method() {
-%      // 1: Some code
-%      extractedMethod();
-%      // 3: More code
-%    }
-%
-%    void extractedMethod() {
-%      // 2: Fragment
-%    }
-%  }
-%    \end{minted}
-%  \end{multicols}
-
 \end{frame}
 
+
 \begin{frame}[fragile]
   \frametitle{The Move Method refactoring}
-  The \refa{Move Method} refactoring is used to move a method from one class to 
-  another. This is useful if a method is using more features of another class 
-  than of the class which it is currently defined.  
+  Move a method from one class to another.
   
 \def\charwidth{4.5pt}
 \def\indent{2*\charwidth}
@@ -379,47 +344,10 @@ class X {
   \end{minted}
 \vfill
 \end{minipage}
-  
-%  \begin{multicols}{2}
-%    \begin{minted}[samepage]{java}
-%  class C {
-%    void method() {
-%      X x = new X();
-%      iBelongInX(x);
-%    }
-%    void iBelongInX(X x) {
-%      x.foo(); x.bar();
-%    }
-%  }
-%  
-%  class X {
-%    void foo(){/*...*/}
-%    void bar(){/*...*/}
-%  }
-%    \end{minted}
-%
-%    \columnbreak
-%
-%    \begin{minted}[samepage]{java}
-%  class C {
-%    void method() {
-%      X x = new X();
-%      x.iBelongInX();
-%    }
-%  }
-%
-%  class X {
-%    void iBelongInX() {
-%      foo(); bar();
-%    }
-%    void foo(){/*...*/}
-%    void bar(){/*...*/}
-%  }
-%    \end{minted}
-%  \end{multicols}
 
 \end{frame}
 
+
 \mysection{The Extract and Move Method refactoring}
 
 \begin{frame}[fragile]
@@ -489,9 +417,21 @@ class Y {
 \end{frame}
 
 \begin{frame}
+  \def\secondlevelmark{\textbullet}
   \begin{itemize}
     \item Composed of \ExtractMethod and \MoveMethod.
-    \item Conseptually, one ``atomic'' operation.
+    \item Conceptually, one ``atomic'' operation.
+      \vspace{2.5pt}
+    \item Implemented as an Eclipse plugin.
+      \vspace{2pt}
+      \begin{itemize} \itemsep3pt
+        \item[\secondlevelmark] The primitive refactorings are supplied by the 
+          Eclipse JDT.
+        \item[\secondlevelmark] The composition work had to be done by us.
+        \item[\secondlevelmark] Not seamless (find the extracted method, move 
+          target etc.).
+
+      \end{itemize}
 
   \end{itemize}
 
@@ -521,27 +461,121 @@ class Y {
 
 \mysection{Automating the refactoring}
 
-\begin{frame}
+\begin{frame}[fragile]
   For any given method: We want to find the best candidate for the 
-  \ExtractAndMoveMethod refactoring.
+  \ExtractAndMoveMethod refactoring, if any exist.
+
+  \begin{minipage}[b]{0.33\textwidth}
+  \hfill\vspace{0.5cm}
+  \end{minipage}\begin{minipage}[t]{0.5\textwidth}
+\def\charwidth{4.5pt}
+\def\indent{2*\charwidth}
+\def\rightColX{32*\charwidth*0}
+\def\lineheight{\baselineskip}
+\def\mintedtop{6.5pt}
 
-  % TODO illustrative picture
+\begin{tikzpicture}[overlay, yscale=-1]
+  \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
+  \draw[overlaybox] (0,\mintedtop+\lineheight*3) rectangle 
+  +(16*\charwidth,2*\lineheight);
+
+  \node[draw opacity=0, text=red] at (20*\charwidth,\mintedtop+\lineheight*4) 
+  {\fontsize{40}{60}\selectfont ?};
+\end{tikzpicture}
+\begin{minted}[samepage]{java}
+void method() {
+  statement_1;
+  statement_2;
+  statement_3;
+  statement_4;
+  statement_5;
+}
+\end{minted}
+  \end{minipage}
 
 \end{frame}
 
-\begin{frame}
-  \frametitle{The refactoring is search-based}
-  The search is based on heuristics, not metrics.
 
+\begin{frame}[fragile]
+\begin{minipage}[t]{0.5\textwidth}
+\def\charwidth{4.75pt}
+\def\indent{2*\charwidth}
+\def\lineheight{\baselineskip}
+\def\mintedtop{5.8pt}
+
+\begin{tikzpicture}[overlay, yscale=-1]
+  \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
+  \draw[overlaybox] (2*\indent,\mintedtop+12*\lineheight) rectangle 
+  +(14*\charwidth,2*\lineheight);
+
+  \draw[overlaybox] (9*\charwidth,\mintedtop+\lineheight) rectangle 
+  +(\charwidth,\lineheight);
+
+  \node[draw opacity=0, text=red] at (12.1*\indent,\mintedtop+12.9*\lineheight) 
+  {text selection};
+
+  \node[draw opacity=0, text=red] at (11.5*\indent,\mintedtop+4*\lineheight) 
+  {move target};
+
+  \draw[-latex,red] (11.5*\indent-5*\charwidth,\mintedtop+3.7*\lineheight) -- 
+  (10.2*\charwidth,\mintedtop+1.5*\lineheight);
+
+\end{tikzpicture}
+\begin{minted}[linenos,samepage]{java}
+class C {
+  A a; B b; boolean bool;
+  void method(int val) {
+    if (bool) {
+      a.foo();
+      a = new A();
+      a.bar();
+    }
+    a.foo();
+    a.bar();
+    switch (val) {
+    case 1:
+      b.a.foo();
+      b.a.bar();
+      break;
+    default:
+      a.foo();
+    }
+  }
+}
+\end{minted}
+\end{minipage}\begin{minipage}[t]{0.5\textwidth}
+  \pause
+  \vspace{1.2cm}
+  A \textbf{candidate} consists of a \emph{text selection} and a \emph{move 
+  target}.\\~\\
+
+  A \textbf{valid text selection} is a text selection that contains all of one 
+  or more consecutive program statements. It is the input to the \ExtractMethod 
+  refactoring.\\~\\
+
+  A \textbf{move target} is a variable (local or field), whose type is the 
+  destination class in the \MoveMethod refactoring.
+
+\end{minipage}
+  
 \end{frame}
 
 
+
 \begin{frame}
-  \frametitle{The search space}
+  \frametitle{Searching}
+  Usually, search-based refactoring is based on metrics.
   \begin{itemize}
-    \item All possible selections of statements in a method.
-    \item Disqualifying illegal selections (avoiding problems).
-  
+    \item Refactor a lot.
+    \item Choose the best candidate based on measurements.
+  \end{itemize}\\~\\
+
+  Our refactoring is based on heuristics.
+  \begin{itemize}
+    \item Up-front analysis.
+    \item A set of assumptions defining what is considered the best candidate.
+    \item No need to actually perform changes (before deciding).
+    \item Search through all valid selections to find the best candidate.
   \end{itemize}
 
 \end{frame}
@@ -550,41 +584,30 @@ class Y {
 \begin{frame}
   \frametitle{Choosing a refactoring candidate}
   \begin{itemize}
-    \item Find the best move target for all selections.
-    \item Choose the best candidate between the selections.
+    \item Search through all selections to find the possible candidates.
+    \item Find the best move target for all the candidates.
+    \item Choose the best among the possible candidates.
+    \item Based on the lengths of the navigation paths and the occurrence 
+      counts.
   
   \end{itemize}
 \end{frame}
 
 
-\begin{frame}
-  \frametitle{Finding a move target for a selection} 
-  
-  \begin{itemize}
-    \item Find possible move targets (prefixes).
-    \item Find the prefixes not suitable as move targets (unfixes).
-    \item Find the best move target among the suitable targets (prefixes minus 
-      unfixes).
-
-  \end{itemize}
-
-\end{frame}
-
 \mysection{Demonstration}
 
-\mysection{Is it any good?}
+\mysection{Case studies}
 
 \begin{frame}
-  \frametitle{Case studies performed}
-  Performed on the \code{org.eclipse.jdt.ui} and \code{no.uio.ifi.refaktor} 
-  projects. The resulting code was analyzed with 
+  Case studies performed on the \code{org.eclipse.jdt.ui} and 
+  \code{no.uio.ifi.refaktor} projects. The resulting code was analyzed with 
   SonarQube.
   \vspace*{\baselineskip}
 
   The Eclipse JDT UI project:
   \begin{itemize}
     \item Over 300,000 lines of code.
-    \item 2,552 methods out of 27,667 methods chosen to be refactored
+    \item 2,552 methods out of 27,667 methods chosen to be refactored.
     \item Approx. 100 minutes.
   
   \end{itemize}
@@ -597,8 +620,8 @@ class Y {
   \begin{itemize}
     \item Measurements show some deterioration regarding coupling.
     \item All improvement not measured, only strict coupling between classes.
-    \item Examples exists where coupling is improved.
-    \item More examples exists where dependencies are introduced.
+    \item Examples exist where coupling is improved.
+    \item More examples exist where dependencies are introduced.
 
   \end{itemize}
 \end{frame}
@@ -608,7 +631,6 @@ class Y {
 \mysection{Conclusions}
 
 \begin{frame}
-  \frametitle{Conclusions}
   \begin{itemize}
     \item Automation is possible.
     \item Efficient enough for some kinds of use.
@@ -619,42 +641,16 @@ class Y {
   \end{itemize}
 \end{frame}
 
+\mysection{Future work}
 
+\begin{frame}
+\begin{itemize}
+  \item Complete analysis.
+  \item Make refactoring safer.
+  \item Improve heuristics to avoid introducing new dependencies.
 
-%\begin{frame}
-%  \frametitle{Demonstration}
-%  \begin{itemize}
-%    \item {The      
-%        \code{LastStatementOfSelectionEndsInReturnOrThrow\-Checker.visit(IfStatement 
-%        node)} method}
-%      \begin{itemize}
-%        \item Extract and Move on selection
-%        \item Extract and Move, search based, on method
-%      \end{itemize}
-%    \item The \code{no.uio.ifi.refaktor} project
-%      \begin{itemize}
-%        \item Extract and Move, search based, over whole project
-%      \end{itemize}
-%  \end{itemize}
-%
-%\end{frame}
-
-
-%\begin{frame}
-%  \frametitle{What is left}
-%  \begin{itemize}
-%    \item Write technical section
-%    \item Write up argument for correctness
-%    \item Define the final case study
-%    \item Run unit tests before and after change
-%    \item Make more examples
-%    \item Metrics?
-%    \item \ldots
-%  \end{itemize}
-% 
-%\end{frame}
-
-\mysection{The end.}
+\end{itemize}
+\end{frame}
 
 \begin{frame}
   \frametitle{References}