Status
Call number
Description
Refactoring is about improving the design of existing code. It is the process of changing a software system in such a way that it does not alter the external behavior of the code, yet improves its internal structure. With refactoring you can even take a bad design and rework it into a good one. This book offers a thorough discussion of the principles of refactoring, including where to spot opportunities for refactoring, and how to set up the required tests. There is also a catalog of more than 40 proven refactorings with details as to when and why to use the refactoring, step by step instructions for implementing it, and an example illustrating how it works The book is written using Java as its principle language, but the ideas are applicable to any OO language.… (more)
Publication
Similar in this library
ISBN
UPC
Collection
Language
Original language
Original publication date
Physical description
User reviews
> Remove duplicated code
> Write smaller classes "Do one thing and do it
> Only expose methods that need to be exposed
> re-write complicated expressions by introducing temporary variables with names that explain the purpose
and so many others. Particularly great for those left maintaining code written by someone else who thought a class containing 2,500 lines of code is fine.
“Refactoring: Improving the
The book was written a decade ago. At that time IDE’s did not support advanced refactorings. Most of the methods described are fully automated in modern IDE’s. This means that you don’t have to follow the text that closely any more.
1. Refactoring, a First Example
The first chapter starts with a simple example. Java code is used throughout the example as well as UML diagrams.
2. Principles in Refactoring
The Why and When of refactoring are discussed. Also we get instructions on what to tell our manager about refactoring. This seems a bit silly to me, since I have never had to explain refactoring to my managers.
3. Bad Smells in Code
“Code Smells” is a frequently used Agile phrase. A phrase I don’t care that much about. Code works or it doesn’t, it can be ugly or unreadable, but it doesn’t smell. The list of “smells” makes sense, however some of the names are downright confusing. For instance, would you be able to tell me what “Refused Bequest” means?
4. Building Tests
This chapter talks about JUnit at length. I am sure you are aware that there are many other unit testing frameworks for programming languages other than Java such as PyUnit. We are told that before you start refactoring, you need to have tests. I think it is more of a chicken/egg dilemma. Sometimes you need to refactor first in order to test. Unit tests and functional tests are mentioned. Integration tests, however are completely ignored. How would you know whether the performance and memory usage of your system remained the same? Clearly, this chapter was written by a software developer, and not by somebody who likes breaking applications, I mean testing applications.
5. Toward a Catalog of Refactorings
Chapter 5 describes the catalog of refactorings to follow. It is the catalog metada in a sense.
6. Composing methods
This chapter is the beginning of the catalog, which forms the “meat” of the book. I am just going to mention a few of the techniques listed in chapter 6.”Extract Method” is one of those refactorings I use on a daily basis. Sometimes things go wrong so we have to do the opposite refactoring “Inline Method”. The author starts using the term “temp” to mean temporary local variables.
7. Moving Features Between Objects
The author admits that he has trouble assigning responsibilities to objects. We are supposed to fix errors with “Move Method”, “Move Field”, “Extract Class” or other refactorings in this chapter.
8. Organizing Data
This chapter discusses a lot of different ways to simplify working with data. For instance, with these refactorings:
Replace Data Value with Object
Replace Array with Object
Also the refactoring “Replace Magic Number with Symbolic Constant” is explained a.k.a “Extract Constant”.
9. Simplifying Conditional Expressions
In my opinion the refactorings in this chapter need to be renamed. Apart from “Decompose Conditional”, which is clear enough. Although “Breaking up Conditional” might have been better.
10. Making Method Calls Simpler
Make method calls simpler by renaming them or replacing long parameter lists by objects. The latter technique could be a problem in concurrent programs. It is common to pass immutable values as parameters. You might not be able to replace them by immutable objects.
11. Dealing with Generalization
Generalization or in OO terms inheritance is a powerful mechanism, that tends to be overused a lot. You can push/pull a method or a field. Inheritance can be replaced by delegation and vice versa.
12. Big Refactorings
In this chapter starts what we can call the “dessert” part. No more simple refactoring recipes. Instead four refactorings that take a considerable amount of time.
13. Refactoring, Reuse and Reality
This chapter is an essay on Refactoring by William Opdyke.
14. Refactoring Tools
IDE’s have come a long way since this book was written. Most of the issues in this chapter are no longer valid.
15. Putting It All Together
This final chapter by Kent Beck is a bit mystical and vague. Those are his own words by the way. Some of the points make sense, but the chapter is written too much in a master talking to an apprentice style.
The book has a list of soundbites at the end. Literally. The fun thing is that you probably have heard or are going to hear a lot of these soundbites. “Refactoring” is a very useful book, albeit too focused on Java. Most recipes would work for another Object Oriented language. I give this book 5 stars out of 5.
Cons: the code smells section is great, but has no actual code
Finally, the exclusive focus on java and OO makes sense, but misses much of the power of functional programming, which removes the need for some types of refactoring entirely. Also, it's a somewhat old version of Java, so the content can feel a little dated.
Overall: an important book to get a sense of refactoring, but the examples leave a lot to be desired.
Good quotes:
With refactoring you find the balance of work changes. You find that design, rather than occurring all up front, occurs continuously during development. You learn from building the system how to improve the design. The resulting interaction leads to a program with a design that stays good as development continues.
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
It reminds me of a statement Kent Beck often makes about himself, "I'm not a great programmer; I'm just a good programmer with great habits."
A heuristic we follow is that whenever we feel the need to comment something, we write a method instead.
On the other hand, I picked up this book at the right time. At work, my project is in the midst of a refactoring project. I am in the middle of
Some of this book is incredibly tedious. It details how to change code from one format to another. It's work that I let my fingers do more of - and my brain less of! But the book also frames how to do this work and why it is so important. It ties together intellectual "loose ends" which might not be tied together by the programmer who simply dives "head first" into the project.
Fowler writes in tandem with a research seminar at the University of Illinois who have pioneered object-oriented techniques in Smalltalk and then Java and C . They tackle the concepts of refactoring more than how to tackle the specifics of coding in a language. I prefer their theoretical approach to more common approaches drenched in technical lingo and programming tools. This book was worth its time.