Excerpt
Preface
What Is Refactoring?
Refactoring is the art of improving the design of existing code. Refactoring provides us with ways to recognize problematic code and gives us recipes for improving it.
What Are the Goals of This Book?
This book is a workbook designed to help you
- Practice recognizing the most important smells (i.e., problems)
- Apply the most important refactoring techniques
- Think more about how to create great code
- Have fun!
To a smaller extent, this book is a reference book with
- A smell finder inside the covers
- A standard format for describing smells
- An appendix listing Java tools supporting refactoring
- An appendix showing key refactorings
Who Is This Book For?
Refactoring being a technique for code, this book then is especially intended for practicing programmers who write and maintain code.
Students can also benefit from refactoring, although I'd expect they'd see the value only after they've had a chance to develop medium-sized or larger programs or had to work in teams (this probably applies to juniors, seniors, and graduate students).
What Background Do You Need?
It would be helpful to have the book, Refactoring: Improving the Design of Existing Code, by Martin Fowler et al. for its catalog of refactorings. (You can read my book and Refactoring at the same time.) Martin and his colleagues have worked out step-by-step instructions for many refactorings, and I will not repeat those in this book. Furthermore, they've provided a fully worked-out example, along with a lot of good discussion and background material. Someone determined to get through this book without that one could probably do it, but I wouldn't recommend it.
The examples in this book are written in Java. This is not because it's the easiest language to refactor, but because it's popular, and the best Java development environments provide automated refactoring support. A C# or C++ programmer has enough reading knowledge of Java to make sense of most of the questions. However, in later parts of the book, you will modify, test, and run larger programs, and this could be problematic for programmers using languages other than Java.
The book Design Patterns, by Gamma et al., describes patterns as "targets for refactoring." It would be helpful to have some familiarity with the ideas in that book because I freely refer to the patterns it mentions. If you're not yet familiar with Design Patterns, let me recommend Steve Metsker's book, Design Patterns Java Workbook, as well.
How to Use This Book
Solving a problem is more challenging than recognizing a solution. There are answers to some problems in the back of the book, but you'll learn more if you try the problems before peeking at the answers. If you work through the problems, you'll probably even find that you disagree with me on some answers. That will be more fun for all of us than if you just look at my answers and nod.
I think it's more fun to work with others (either a partner or in a small group), but I recognize that isn't always possible.
The later (longer) examples need to be done at a computer. Looking for problems, and figuring out how to solve them, is different when you're looking at a program in your environment.