]> git.uio.no Git - ifi-stolz-refaktor.git/blob - presentation/master-presentation-erlenkr.tex
Presentation: spelling
[ifi-stolz-refaktor.git] / presentation / master-presentation-erlenkr.tex
1 % Law of demeter?
2 \documentclass[USenglish,9pt]{beamer}
3 \usepackage[utf8]{inputenc}
4 \usepackage[T1]{fontenc}
5 \usepackage{lmodern}
6 \usepackage{babel,textcomp}
7 \usepackage[style=alphabetic,backend=biber,doi=false,isbn=false]{biblatex}
8 \usepackage{babel,textcomp,csquotes}
9 \usepackage{xspace}
10
11 \usepackage{tikz}
12 \usetikzlibrary{shapes,snakes,trees,arrows,shadows,positioning,calc}
13
14 \usepackage{varioref}
15 %\usepackage[hidelinks]{hyperref}
16 \usepackage{cleveref}
17
18 \usepackage{amsthm}
19 \usepackage{mathtools}
20
21 \usepackage{verbatim}
22 \usepackage{minted}
23 \usepackage{multicol}
24 %\usemintedstyle{bw}
25 \usemintedstyle{default}
26
27 \usetheme{Ifi}
28
29 \theoremstyle{definition}
30 \newtheorem*{wordDef}{Definition}
31 \newtheorem*{mytheorem}{Theorem}
32 \newcommand{\mydefinition}[1]{\begin{wordDef}#1\end{wordDef}}
33
34 \newcommand{\citing}[1]{~\cite{#1}}
35
36 \newcommand{\code}[1]{\texttt{\textbf{#1}}}
37 \newcommand{\type}[1]{\code{#1}}
38 \newcommand{\method}[1]{\type{#1}}
39 \newcommand{\var}[1]{\type{#1}}
40
41 \newcommand{\name}[1]{#1}
42 \newcommand{\tit}[1]{\emph{#1}}
43 \newcommand{\refa}[1]{\emph{#1}}
44 \newcommand{\pattern}[1]{\emph{#1}}
45 \newcommand{\metr}[1]{\emph{#1}}
46 \newcommand{\ExtractMethod}{\refa{Extract Method}\xspace}
47 \newcommand{\MoveMethod}{\refa{Move Method}\xspace}
48 \newcommand{\ExtractAndMoveMethod}{\refa{Extract and Move Method}\xspace}
49
50 \newcommand{\mysection}[1]{
51   \section{#1}
52   \begin{frame}
53     \begin{center}{\Huge #1}\end{center}
54   \end{frame}
55 }
56
57 \def\mintedframesep{11pt}
58
59 \def\thetitle{Automated Composition of Refactorings}
60 \def\subtitle{Implementing and evaluating a search-based Extract and Move Method refactoring}
61 \title{\thetitle}
62 \author{Erlend Kristiansen}
63
64
65 %% HEADLINE %%
66 \setbeamertemplate{headline}{%
67   \ifnum\insertframenumber>1
68 \leavevmode%
69   \hbox{%
70     \begin{beamercolorbox}[wd=\paperwidth,ht=5ex,dp=1.125ex]{palette 
71       quaternary}%
72     \insertsectionnavigationhorizontal{\paperwidth}{}{\hskip0pt plus1filll}
73     \end{beamercolorbox}%
74   }
75   \fi
76 }
77
78 \makeatletter
79 \def\insertsectionnavigationhorizontal#1#2#3{%
80  \hbox to #1{{%
81    \def\slideentry##1##2##3##4##5##6{}%
82    #2\hskip.3cm%
83    \newdimen\tmp@parbox%
84    \setlength\tmp@parbox{#1}%
85    \addtolength\tmp@parbox{-.6cm}%
86    \parbox{\tmp@parbox}{\raggedleft%
87      \usebeamerfont{section in head/foot}\usebeamercolor[fg]{section in head/foot}%
88      \setbox\beamer@sectionbox=\hbox{}%
89      \ht\beamer@sectionbox=1.875ex%
90      \dp\beamer@sectionbox=0.75ex%
91      \hskip-1.875ex plus-1fill\dohead%
92      \box\beamer@sectionbox}\hfil\hskip.3cm%
93      #3}}}
94 \makeatother
95
96 %% Remove navigation 
97 \setbeamertemplate{navigation symbols}{}
98
99 \bibliography{bibliography/master-thesis-erlenkr-bibliography}
100
101 \begin{document}
102
103 \begin{frame}
104   \frametitle{\thetitle}
105   {\subtitle}
106   \vspace*{\baselineskip}
107
108   {\small \emph{Erlend Kristiansen, 2014}}
109   \vspace*{\baselineskip}
110 \end{frame}
111
112 \section{Definitions}
113
114 \begin{frame}
115   \frametitle{Refactoring, as defined in the literature}
116
117   \begin{quote}
118     \emph{Refactoring} (noun): a change made to the internal structure
119     of software to make it easier to understand and cheaper to modify without 
120     changing its observable behavior.~\cite[p.~53]{refactoring}
121   \end{quote}
122 \end{frame}
123
124 \begin{frame}
125   \frametitle{An alternative definition of refactoring}
126
127   \begin{definition}
128     A \emph{refactoring} is a transformation
129     done to a program without altering its external behavior.
130   \end{definition}
131 \end{frame}
132
133 \begin{frame}
134   \frametitle{Primitive and composite refactorings}
135   \begin{definition}
136     A \emph{primitive refactoring} is a refactoring that cannot be expressed in 
137     terms of other refactorings.
138
139   \end{definition}
140
141   \begin{definition}
142     A \emph{composite refactoring} is a refactoring that can be expressed in 
143     terms of two or more other refactorings.
144   \end{definition}
145 \end{frame}
146
147 \mysection{Motivation}
148
149 \begin{frame}[fragile]
150 \def\charwidth{4.5pt}
151 \def\indent{2*\charwidth}
152 \def\rightColX{32*\charwidth*0}
153 \def\lineheight{\baselineskip}
154 \def\mintedtop{22.5pt}
155
156 \begin{minipage}[t]{0.45\textwidth}
157 \begin{tikzpicture}[overlay, yscale=-1]
158   \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
159   % Bad
160   \draw[overlaybox] (\indent,\mintedtop+\lineheight*3) rectangle 
161   +(16*\charwidth,2*\lineheight);
162 \end{tikzpicture}
163 \begin{minted}[linenos,samepage,frame=topline,label={Bad},framesep=\mintedframesep]{java}
164 class C {
165   A a; B b; X x;
166   void method() {
167     x.y.foo();
168     x.y.bar();
169   }
170 }
171 class X {
172   Y y;
173 }
174 class Y {
175   void foo(){/*...*/}
176   void bar(){/*...*/}
177 }
178 \end{minted}
179 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
180 \begin{tikzpicture}[overlay, yscale=-1]
181   \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
182   % Good
183   \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle 
184   +(16*\charwidth,\lineheight);
185
186   \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*8) rectangle 
187   +(19*\charwidth,4*\lineheight);
188
189   \draw[-latex,red] (-3,2.5) -- (-0.1,\mintedtop+\lineheight*9);
190   
191 \end{tikzpicture}
192 \begin{minted}[linenos,samepage,frame=topline,label={Good},framesep=\mintedframesep]{java}
193 class C {
194   A a; B b; X x;
195   void method() {
196     x.fooBar();
197   }
198 }
199 class X {
200   Y y;
201   void fooBar() {
202     y.foo();
203     y.bar();
204   }
205 }
206 class Y {
207   void foo(){/*...*/}
208   void bar(){/*...*/}
209 }
210   \end{minted}
211 \vfill
212 \end{minipage}
213 \end{frame}
214
215 \begin{frame}
216   \begin{itemize}
217     \item Get rid of long navigation paths.
218     \item Move operations closer to the data they manipulate.
219     \item Reduce coupling.
220     \item Increase maintainability.
221   
222   \end{itemize}
223
224 \end{frame}
225
226 \mysection{The primitive refactorings}
227
228 \begin{frame}[fragile]
229   \frametitle{The Extract Method refactoring}
230   Extract a fragment of code into a new method.
231
232 \def\charwidth{4.5pt}
233 \def\indent{2*\charwidth}
234 \def\rightColX{32*\charwidth*0}
235 \def\lineheight{\baselineskip}
236 \def\mintedtop{6.5pt}
237
238 \begin{minipage}[t]{0.45\textwidth}
239 \begin{tikzpicture}[overlay, yscale=-1]
240   \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
241   % Bad
242   \draw[overlaybox] (\indent,\mintedtop+\lineheight*3) rectangle 
243   +(16*\charwidth,2*\lineheight);
244 \end{tikzpicture}
245 \begin{minted}[linenos,samepage]{java}
246 class C {
247   A a; B b; X x;
248   void method() {
249     x.y.foo();
250     x.y.bar();
251   }
252 }
253 \end{minted}
254 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
255 \begin{tikzpicture}[overlay, yscale=-1]
256   \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
257   % Good
258   \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle 
259   +(16*\charwidth,\lineheight);
260
261   \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*5) rectangle 
262   +(19*\charwidth,4*\lineheight);
263
264   \draw[-latex,red] (-3,1.8) -- (-0.1,\mintedtop+\lineheight*6);
265   
266 \end{tikzpicture}
267 \begin{minted}[linenos,samepage]{java}
268 class C {
269   A a; B b; X x;
270   void method() {
271     fooBar();
272   }
273   void fooBar() {
274     x.y.foo();
275     x.y.bar();
276   }
277 }
278   \end{minted}
279 \vfill
280 \end{minipage}
281
282 \end{frame}
283
284
285 \begin{frame}[fragile]
286   \frametitle{The Move Method refactoring}
287   Move a method from one class to another.
288   
289 \def\charwidth{4.5pt}
290 \def\indent{2*\charwidth}
291 \def\rightColX{32*\charwidth*0}
292 \def\lineheight{\baselineskip}
293 \def\mintedtop{6.5pt}
294
295 \begin{minipage}[t]{0.45\textwidth}
296 \begin{tikzpicture}[overlay, yscale=-1]
297   \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
298   % Bad
299   \draw[overlaybox] (0,\mintedtop+\lineheight*5) rectangle 
300   +(19*\charwidth,4*\lineheight);
301 \end{tikzpicture}
302 \begin{minted}[linenos,samepage]{java}
303 class C {
304   A a; B b; X x;
305   void method() {
306     fooBar();
307   }
308   void fooBar() {
309     x.y.foo();
310     x.y.bar();
311   }
312 }
313 class X {
314   Y y;
315 }
316 \end{minted}
317 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
318 \begin{tikzpicture}[overlay, yscale=-1]
319   \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
320   % Good
321   \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle 
322   +(16*\charwidth,\lineheight);
323
324   \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*8) rectangle 
325   +(19*\charwidth,4*\lineheight);
326
327   \draw[-latex,red] (-2.8,2.9) -- (-0.1,\mintedtop+\lineheight*9.5);
328   
329 \end{tikzpicture}
330 \begin{minted}[linenos,samepage]{java}
331 class C {
332   A a; B b; X x;
333   void method() {
334     x.fooBar();
335   }
336 }
337 class X {
338   Y y;
339   void fooBar() {
340     y.foo();
341     y.bar();
342   }
343 }
344   \end{minted}
345 \vfill
346 \end{minipage}
347
348 \end{frame}
349
350
351 \mysection{The Extract and Move Method refactoring}
352
353 \begin{frame}[fragile]
354 \def\charwidth{4.5pt}
355 \def\indent{2*\charwidth}
356 \def\rightColX{32*\charwidth*0}
357 \def\lineheight{\baselineskip}
358 \def\mintedtop{22.5pt}
359
360 \begin{minipage}[t]{0.45\textwidth}
361 \begin{tikzpicture}[overlay, yscale=-1]
362   \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
363   % Before
364   \draw[overlaybox] (\indent,\mintedtop+\lineheight*3) rectangle 
365   +(16*\charwidth,2*\lineheight);
366 \end{tikzpicture}
367 \begin{minted}[linenos,samepage,frame=topline,label={Before},framesep=\mintedframesep]{java}
368 class C {
369   A a; B b; X x;
370   void method() {
371     x.y.foo();
372     x.y.bar();
373   }
374 }
375 class X {
376   Y y;
377 }
378 class Y {
379   void foo(){/*...*/}
380   void bar(){/*...*/}
381 }
382 \end{minted}
383 \end{minipage}\hspace{0.1\textwidth}\pause\begin{minipage}[t]{0.45\textwidth}
384 \begin{tikzpicture}[overlay, yscale=-1]
385   \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
386   % After
387   \draw[overlaybox] (\rightColX+\indent,\mintedtop+\lineheight*3) rectangle 
388   +(16*\charwidth,\lineheight);
389
390   \draw[overlaybox] (\rightColX,\mintedtop+\lineheight*8) rectangle 
391   +(19*\charwidth,4*\lineheight);
392
393   \draw[-latex,red] (-3,2.5) -- (-0.1,\mintedtop+\lineheight*9);
394   
395 \end{tikzpicture}
396 \begin{minted}[linenos,samepage,frame=topline,label={After},framesep=\mintedframesep]{java}
397 class C {
398   A a; B b; X x;
399   void method() {
400     x.fooBar();
401   }
402 }
403 class X {
404   Y y;
405   void fooBar() {
406     y.foo();
407     y.bar();
408   }
409 }
410 class Y {
411   void foo(){/*...*/}
412   void bar(){/*...*/}
413 }
414   \end{minted}
415 \vfill
416 \end{minipage}
417 \end{frame}
418
419 \begin{frame}
420   \def\secondlevelmark{\textbullet}
421   \begin{itemize}
422     \item Composed of \ExtractMethod and \MoveMethod.
423     \item Conceptually, one ``atomic'' operation.
424       \vspace{2.5pt}
425     \item Implemented as an Eclipse plugin.
426       \vspace{2pt}
427       \begin{itemize} \itemsep3pt
428         \item[\secondlevelmark] The primitive refactorings are supplied by the 
429           Eclipse JDT.
430         \item[\secondlevelmark] The composition work had to be done by us.
431         \item[\secondlevelmark] Not seamless (find the extracted method, move 
432           target etc.).
433
434       \end{itemize}
435
436   \end{itemize}
437
438 \end{frame}
439
440 \mysection{Research questions}
441
442 \begin{frame}
443   Main research question:
444   \begin{quote}
445     Is it possible to automate the analysis and execution of the 
446     \ExtractAndMoveMethod refactoring, and do so for all of the code of a larger 
447     project?
448   \end{quote}
449   
450   Secondary questions:
451   \begin{itemize}
452     \item Can we do this efficiently?
453     \item Can we perform changes safely?
454     \item Can we improve the quality of source code?
455     \item How can the automation of the refactoring be helpful?
456   
457   \end{itemize}
458   
459 \end{frame}
460
461
462 \mysection{Automating the refactoring}
463
464 \begin{frame}[fragile]
465   For any given method: We want to find the best candidate for the 
466   \ExtractAndMoveMethod refactoring, if any exist.
467
468   \begin{minipage}[b]{0.33\textwidth}
469   \hfill\vspace{0.5cm}
470   \end{minipage}\begin{minipage}[t]{0.5\textwidth}
471 \def\charwidth{4.5pt}
472 \def\indent{2*\charwidth}
473 \def\rightColX{32*\charwidth*0}
474 \def\lineheight{\baselineskip}
475 \def\mintedtop{6.5pt}
476
477 \begin{tikzpicture}[overlay, yscale=-1]
478   \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
479   \draw[overlaybox] (0,\mintedtop+\lineheight*3) rectangle 
480   +(16*\charwidth,2*\lineheight);
481
482   \node[draw opacity=0, text=red] at (20*\charwidth,\mintedtop+\lineheight*4) 
483   {\fontsize{40}{60}\selectfont ?};
484 \end{tikzpicture}
485 \begin{minted}[samepage]{java}
486 void method() {
487   statement_1;
488   statement_2;
489   statement_3;
490   statement_4;
491   statement_5;
492 }
493 \end{minted}
494   \end{minipage}
495
496 \end{frame}
497
498
499 \begin{frame}[fragile]
500 \begin{minipage}[t]{0.5\textwidth}
501 \def\charwidth{4.75pt}
502 \def\indent{2*\charwidth}
503 \def\lineheight{\baselineskip}
504 \def\mintedtop{5.8pt}
505
506 \begin{tikzpicture}[overlay, yscale=-1]
507   \tikzstyle{overlaybox}=[fill=gray,opacity=0.2]
508   \draw[overlaybox] (2*\indent,\mintedtop+12*\lineheight) rectangle 
509   +(14*\charwidth,2*\lineheight);
510
511   \draw[overlaybox] (9*\charwidth,\mintedtop+\lineheight) rectangle 
512   +(\charwidth,\lineheight);
513
514   \node[draw opacity=0, text=red] at (12.1*\indent,\mintedtop+12.9*\lineheight) 
515   {text selection};
516
517   \node[draw opacity=0, text=red] at (11.5*\indent,\mintedtop+4*\lineheight) 
518   {move target};
519
520   \draw[-latex,red] (11.5*\indent-5*\charwidth,\mintedtop+3.7*\lineheight) -- 
521   (10.2*\charwidth,\mintedtop+1.5*\lineheight);
522
523 \end{tikzpicture}
524 \begin{minted}[linenos,samepage]{java}
525 class C {
526   A a; B b; boolean bool;
527   void method(int val) {
528     if (bool) {
529       a.foo();
530       a = new A();
531       a.bar();
532     }
533     a.foo();
534     a.bar();
535     switch (val) {
536     case 1:
537       b.a.foo();
538       b.a.bar();
539       break;
540     default:
541       a.foo();
542     }
543   }
544 }
545 \end{minted}
546 \end{minipage}\begin{minipage}[t]{0.5\textwidth}
547   \pause
548   \vspace{1.2cm}
549   A \textbf{candidate} consists of a \emph{text selection} and a \emph{move 
550   target}.\\~\\
551
552   A \textbf{valid text selection} is a text selection that contains all of one 
553   or more consecutive program statements. It is the input to the \ExtractMethod 
554   refactoring.\\~\\
555
556   A \textbf{move target} is a variable (local or field), whose type is the 
557   destination class in the \MoveMethod refactoring.
558
559 \end{minipage}
560   
561 \end{frame}
562
563
564
565 \begin{frame}
566   \frametitle{Searching}
567   Usually, search-based refactoring is based on metrics.
568   \begin{itemize}
569     \item Refactor a lot.
570     \item Choose the best candidate based on measurements.
571   \end{itemize}\\~\\
572
573   Our refactoring is based on heuristics.
574   \begin{itemize}
575     \item Up-front analysis.
576     \item A set of assumptions defining what is considered the best candidate.
577     \item No need to actually perform changes (before deciding).
578     \item Search through all valid selections to find the best candidate.
579   \end{itemize}
580
581 \end{frame}
582
583
584 \begin{frame}
585   \frametitle{Choosing a refactoring candidate}
586   \begin{itemize}
587     \item Search through all selections to find the possible candidates.
588     \item Find the best move target for all the candidates.
589     \item Choose the best among the possible candidates.
590     \item Based on the lengths of the navigation paths and the occurrence 
591       counts.
592   
593   \end{itemize}
594 \end{frame}
595
596
597 \mysection{Demonstration}
598
599 \mysection{Case studies}
600
601 \begin{frame}
602   Case studies performed on the \code{org.eclipse.jdt.ui} and 
603   \code{no.uio.ifi.refaktor} projects. The resulting code was analyzed with 
604   SonarQube.
605   \vspace*{\baselineskip}
606
607   The Eclipse JDT UI project:
608   \begin{itemize}
609     \item Over 300,000 lines of code.
610     \item 2,552 methods out of 27,667 methods chosen to be refactored.
611     \item Approx. 100 minutes.
612   
613   \end{itemize}
614
615 \end{frame}
616
617
618 \begin{frame}
619   \frametitle{The case studies are inconclusive}
620   \begin{itemize}
621     \item Measurements show some deterioration regarding coupling.
622     \item All improvement not measured, only strict coupling between classes.
623     \item Examples exist where coupling is improved.
624     \item More examples exist where dependencies are introduced.
625
626   \end{itemize}
627 \end{frame}
628
629 \mysection{Demonstration continued}
630
631 \mysection{Conclusions}
632
633 \begin{frame}
634   \begin{itemize}
635     \item Automation is possible.
636     \item Efficient enough for some kinds of use.
637     \item Difficult not to break source code.
638     \item Code is not improved in most cases.
639     \item Not particularly useful in its current state.
640   
641   \end{itemize}
642 \end{frame}
643
644 \mysection{Future work}
645
646 \begin{frame}
647 \begin{itemize}
648   \item Complete analysis.
649   \item Make refactoring safer.
650   \item Improve heuristics to avoid introducing new dependencies.
651
652 \end{itemize}
653 \end{frame}
654
655 \begin{frame}
656   \frametitle{References}
657   \printbibliography
658 \end{frame}
659
660 \end{document}