]> git.uio.no Git - ifi-stolz-refaktor.git/blame - thesis/master-thesis-erlenkr.tex
Starting a section about refactoring and it's impact on software quality.
[ifi-stolz-refaktor.git] / thesis / master-thesis-erlenkr.tex
CommitLineData
7c28933b 1\documentclass[USenglish]{ifimaster}
571ef294 2\usepackage{import}
7c28933b 3\usepackage[utf8]{inputenc}
9ff90080
EK
4\usepackage[T1]{fontenc,url}
5\urlstyle{sf}
571ef294
EK
6\usepackage{babel,textcomp,csquotes,ifimasterforside,varioref,graphicx}
7\usepackage[style=numeric-comp]{biblatex}
8%\usepackage[backend=biber,style=numeric-comp]{biblatex}
12c254af 9\usepackage{amsthm}
9ff90080 10
12c254af
EK
11\theoremstyle{plain}
12\newtheorem*{wordDef}{Definition}
13
14\newcommand{\definition}[1]{\begin{wordDef}#1\end{wordDef}}
9ff90080 15
7c28933b
EK
16
17\title{Refactoring}
18\subtitle{An essay}
19\author{Erlend Kristiansen}
20
21\bibliography{bibliography/master-thesis-erlenkr-bibliography}
9ff90080
EK
22
23\begin{document}
7c28933b 24\ififorside{}
9ff90080 25\frontmatter{}
9ff90080
EK
26
27
28\chapter*{Abstract}
29Empty document.
30
31\tableofcontents{}
32\listoffigures{}
33\listoftables{}
34
35\chapter*{Preface}
36
37\mainmatter{}
7c28933b 38
9ff90080
EK
39\part{Introduction}
40
51a854d4 41\chapter{Refactoring in general}
7c28933b 42
51a854d4 43\section*{What is refactoring?}
7c28933b 44
51a854d4
EK
45This question is best answered dividing the answer into two parts. First
46defining the concept of a refactoring, then discuss what the dicipline of
47refactoring is all about. And to make it clear already from the beginning: The
48dicussions in this report must me seen in the context of object oriented
49programming languages. It may be obvious, but much of the material will not make
50much sense otherwise, although some of the techniques may be applicable to
51sequential languages, then possibly in other forms.
52
53\subsection*{Defining a refactoring}
12c254af 54Well, this is the easy one.
51a854d4 55\definition{A refactoring is a transformation
12c254af
EK
56done to a program without altering its external behaviour.}
57So a refactoring changes how the \emph{code} of a program is percepted by the
58\emph{programmer}, and not the behaviour experienced by any user of the program.
59The semantic meaning is preserved. To \emph{refactor} is (quoting Martin Fowler)
7c28933b
EK
60\begin{quote}
61 \ldots to restructure software by applying a series of refactorings without
9a55a5bc 62 changing its observable behaviour. \cite{refactoring} % page 54, definition
7c28933b
EK
63\end{quote}
64
51a854d4 65\subsection*{The dicipline of refactoring}
12c254af
EK
66This one is a little harder. To get a grasp of what the dicipline of refactoring
67is about, we better answer this question: \emph{Why do people refactor?}
68Possible answers could include: ``To remove duplication'' or ``to break up long
69methods''. Practitioners of the art of Design Patterns \cite{dp} could say that
70they do it to introduce a long-needed pattern to their program's design. So it's
71safe to say that peoples intentions is to make their programs \emph{better} in
72some sense. But what aspects of the programs are becoming improved?
51a854d4
EK
73
74As already mentioned, people often refactor to get rid of duplication. Moving
75identical or similar code into methods, and maybe pushing those around in their
76hierarchies. Making template methods for overlapping algorithms and so on. It's
12c254af
EK
77all about gathering what belongs together and putting it all in one place. And
78the result? The code is easier to maintain, due to removing the implicit
51a854d4
EK
79coupling between the code snippets and getting rid of the almost sure path to
80bugs.
81
82The same people find out that their program contains a lot of long and
83hard-to-grasp methods. Then what do they do? They begin dividing their methods
84into smaller ones, using the \emph{Extract Method} \cite{refactoring}. All of a
85sudden they may discover something about their program that they weren't aware
86of before; revealing bugs they didn't know about or couldn't find due to the
87complex structure of their program. Making the methods smaller and giving good
88names to the new ones clarifies the algorithms and enhances the
89\emph{understandability} of the program. This makes simple refactoring an
90excellent method for exploring unknown program code, or code that you had
91forgotten that you wrote!
92
93The word \emph{simple} came up in the last section. In fact, most basic
94refactorings are simple. The true power of them are revealed first when they are
95combined into larger --- higher level --- refactorings. Often the goal of such a
96serie of refactorings is a design pattern. Thus the \emph{design} can be evolved
97throughout the lifetime of a program, opposed to designing up-front. It's all
98about being structured and taking small steps to improve the design.
99
100Many refactorings are aimed at lowering the coupling between different classes
101and different layers of logic. Say for instance that the coupling between the
102user interface and the business logic of a program is lowered. Then the business
103logic of the program could much easier be the target of automated tests,
0b0567f2
EK
104increasing the productivity in the software development process. It would also
105be much easier to distribute the different parts of the program if they were
106decoupled.
107
108Another effect of refactoring is that with the increased separation of concerns
9a55a5bc 109coming out of many refactorings, the \emph{tunability} is improved. When
0b0567f2
EK
110profiling programs, the problem parts are narrowed down to smaller parts of the
111code and optimization can be performed only where needed.
112
113Refactoring program code --- with a goal in mind --- give the code itself more
114value. That is in the form of robustness, understandability and maintainability.
115With the first as an obvious advantage, but with the following two being also
116very important in software development. By incorporating refactoring in the
117development process, bugs are found faster, new functionality is added more
118easily and code is easier to understand by the next person exposed to it, which
119might as well be the person who wrote it. So, refactoring can also add to the
120monetary value of a business, by increased productivity of the develompment
121process in the long run.
9ff90080
EK
122
123
12c254af 124% \part{The project}
9ff90080 125
12c254af 126% \chapter{Planning the project}
9ff90080
EK
127
128
12c254af 129%\part{Conclusion}
9ff90080 130
12c254af 131%\chapter{Results}
9ff90080
EK
132
133
9a55a5bc
EK
134
135\section*{The impact on software quality}
136
137\subsection*{What is meant by quality?}
138The term \emph{software quality} can have many meanings. It all depends on the
139context we put it in. If we look at it with the eyes of a software developer, it
140usually mean that the software is easily maintainable and testable, or in other
141words, that it is \emph{well designed}. This often correlates with the
142management scale, where \emph{keeping the schedule} and \emph{customer
143satisfaction} is at the center. (Although refactoring isn't always recognized
144as the best way to achieve these goals.) From the customers point of view, in
145addition to good usability,
146\emph{performance} and \emph{lack of bugs} is always appreciated, measurements
147that are also shared by the software developer. (In addition, such things as
148good documentation could be measured, but this is out of the scope of this
149document.)
150
151\subsection*{The impact on performance}
152\begin{quote}
153 Refactoring certainly will make software go more slowly, but it also makes the
154 software more amenable to performance tuning. \cite{refactoring} % page 69
155\end{quote}
156There is a common belief that refactoring compromises performance, due to
157increased degree of indirection and that polymorphism is slower than
158conditionals.
159
160In a survey, Demeyer \cite{demeyer2002} disproves this view in the case of
161polymorphism. He is doing an experiment on, what he calls, ``Transform Self Type
162Checks'' where you introduce a new polymorphic method and a new class hierarchy
163to get rid of a class' type checking of a ``type attribute``. He uses this kind
164of transformation to represent other ways of replacing conditionals with
165polymorphism as well. The experiment is performed on the C++ programming
166language and with three different compilators and platforms. Demeyer concludes
167that, with compiler optimization turned on, polymorphism beats middle to large
168sized if-statements and does as well as case-statements. (In accordance with his
169hypethesis, due to similarities between the way C++ handles polymorphism and
170case-statements.)
171\begin{quote}
172 The interesting thing about performance is that if you analyze most programs,
173 you find that they waste most of their time in a small fraction of the code.
174 \cite{refactoring}
175\end{quote}
176So, although an increased amount of method calls could potentially slow down
177programs, one should avoid premature optimization and sacrificing good design,
178leaving the performance tuning until after profiling the software and having
179isolated the actual problem areas.
180
181
9ff90080
EK
182\backmatter{}
183\printbibliography
184\end{document}