Let me start this lesson by discussing what is refactoring.
Refactoring is the process of applying transformation or refactoring to a
program. So as to obtain a refactor program. With an
improved design but with same functionality as the original program. So
key aspect of refactoring is the fact that refactoring should
be somatic to perserving So what is the main goal of
refactoring? The goal is to keep the program readable, understandable, and
maintainable as we evolve it. And to do this by eliminating
small problems soon, so that you can avoid big trouble later. And
I want to stress once more a key feature of refactoring, which
is the fact that it is behavior per serving. But how can
we ensure that the refactoring is behavior per serving? In other words,
how can we ensure that the program does the same thing before
and after applying a refactoring. So what we would like to do
is to have some guarantee that, that happens. And unfortunately in general,
there are no guarantees. But something we can do is to test
the code. For example, we can write tests that exercise the
parts of the program affected by the refactoring, and if we're in
a [INAUDIBLE] context, we might already have plenty of test cases
that exercise that part of the code. So we might just have
to rerun the test cases after the refactoring. And in fact,
that's a very advantageous situation, and that's a very good use of
existing test cases. And I want to make sure that you remember,
and that you beware that tests provide no guarantees. Testing can only
show the presence of defects, but cannot demonstrate their absence.
So we can use testing to get confidence in our
refactorings, but we can't really guarantee that the refactorings are
behavior preserving. I'd also like to point out that for some
simple refactoring, we can use a static analysis to actually
provide these guarantees. And in fact we will see examples of
such refactorings that are incorporated into IDs and that leverage
these kinds of analysis to perform refactoring in a safe way.