Announcing the Second Edition of "Refactoring"
I was lucky enough to work with Kent Beck on the C3 project that birthed Extreme Programming. There was a great deal I learned (and am still learning) from Kent, but one thing that really stood out was they approach he took to continually reworking the code base to keep it healthy, an approach that went under the then-unknown name of "Refactoring". In my other consulting work I stressed how valuable a technique this is, but couldn't point people to a book to learn about it, so I ended up writing it myself. It was published just before the 20th Century ended.
That's nearly twenty years ago, and the technique is now more widely
known, although often not executed as well as it should be. The book has
also held up pretty well, and I think you can take this old book and still
learn how to refactor pretty much as well as you could all those years ago.
But the book shows its age, the use of
very gray hair.
So over the years I've been thinking about revising it, but I have also been reluctant. After all it still teaches the technique perfectly well, and second editions have a horrible habit of not improving on the original. But a further force has been tugging at me. At the time I wrote it, it was becoming mainstream to consider classes as the dominant structuring the mechanism for code. These days, however, we see other structures playing a greater role. Classes still are valuable, in my view, but our refactoring needs to be less centered around them, realizing that they can come and go as code is trained into new shapes.
During 2015 and early 2016 I wrote a series of essays exploring various circumstances for refactoring, this helped me get a feel for if I should tackle a rewrite, and if so, how. By mid 2016 I was ready to commence the work in anger.  If you've been wondering why I haven't been writing as much for martinfowler.com as I used to, it was because my writing energy has been focused on the book since then.
Changes in the Second Edition
The changes are both very minor and all-encompassing. They are minor because the basic structure of the book hasn't changed. I begin with an opening example, a chapter of principles, a survey of "code smells", and an introduction to testing. The bulk of the book is a catalog of refactorings and of those 68 refactorings, all but 10 are still present, and I've added 17 new ones.
Despite this lack of change in the overall book structure, the changes to the words on pages is huge. Every chapter and refactoring has been rewritten, mostly from near scratch. I rarely had decent opportunities to cut and paste text from the old edition.
The reorientation towards a less class-centered view is a large part of this. Although that may sound as simple as changing the name of "Extract Method" to "Extract Function", it did entail rethinking all aspects of every refactoring. I needed to reconsider the motivation, often feeling that it needed to be reframed. The mechanics needed at least a detailed review, often a complete rewrite. I wasn't keeping detailed notes on this, but my feel is that for every relatively simple import of an old refactoring, there were two that required a complete rethink.
However there is another change, which in a way isn't that important, but is bound to get a lot of attention. The examples are no longer in Java.
When I choose a language for examples in my writing, I think primarily of the reader. I ask "what language will help the most readers understand the concepts in the book?" Refactoring isn't a language specific book, its advice may have been explained with the help of examples in Java, but the refactorings apply to most languages. I picked Java because I felt the most people would be able to understand the code examples if they were written in Java. That was the case in 1997, but how about in 2017?
A Web-First Book
The world-wide web has made an enourmous impact on our society, particularly affecting how we gather information. When I wrote the first edition, most of the knowledge about software development was transferred through print. Now I gather most of my information online. This has presented a challenge for authors like myself, is there still a role for books, and what should they look like?
I believe there still is role for books like this, but they need to change. The value of a book is a large body of knowledge, put together in a cohesive fashion. In writing this book I need to gather together lots of refactorings, and organize them in a consistent and integrated manner.
But that integrated whole is an abstract literary work that, while traditionally represented by a paper book, need not be in the future. Most of the book industry still sees the paper book as the primary representation, and while we've enthusiastically adopted ebooks, these are just electronic representations of an original work based on the notion of a paper book.
With this book, I'm exploring a different approach. I think of the canonical form of this book as the web site. The paper book is a selection of material from the web site, arranged in a manner that makes sense for print. It doesn't attempt to include all the refactorings in the canonical book, particularly since I may well add more refactorings to the canonical web book in the future.
Our intention is that when you buy a copy of Refactoring, 2nd Ed, you might buy it at a bookstore in its physical form, or online in any form. The most essential thing you get for your money is the access code that gives you permanent access to the web site. You can read the physical book, and access the web site whenever you need.
This raises a question of what role ebooks (such as epubs and kindle books) should play. There is a strong argument that they should contain all the information on the web site, after all physical size isn't a factor, and ebooks can be updated easily if I add new material. However the book industry doesn't think that way, they expect ebooks to have the same content as the physical books, so the ebook versions of refactoring will follow that principle, at least for now.
I've been working on this book for over year, but haven't made any announcement of this on my blog. I haven't kept this a great secret, anyone who knows me, has been aware of this work, but I avoided making an announcement because I wasn't sure how and when the effort would develop. It's one thing to start a book, but quite another to finish one. And the existing book is still a fine way to learn about refactoring, the new edition is a refresh, not a necessary replacement.
I'm posting this now because the end is finally in sight, and I'm pretty confident that I'll get there in the foreseeable future. At this point I've sent a first draft to a panel of technical reviewers and expect their replies shortly. Soon I'll have to work through their feedback. I'm hoping there won't be any drastic changes, because I've had an ongoing review panel that's been reviewing small chunks of the new edition as I've been writing it.
Assuming no drastic changes, this means we should "release to production" at the beginning of summer. The production team will then copy-edit the entire book and format the print edition. That will take most of the summer, and then the print edition will go out for production. We also have to arrange the website, which will be done via Pearson, and set things up so I can release material to it easily.
Our target for the print edition of the book is to have it available during the fall of this year. The website should be up no later than that, and hopefully will appear somewhat earlier.
That's the outline of the plan so far, but of course plans don't always match reality. I'll announce any developments on my twitter and RSS feeds.
1: My repository shows its first commit on May 25th 2016
2: When I wrote the first edition I was frustrated that I was having to write the book's code in a language that was significantly worse than the language I preferred (Smalltalk). Little did I know that I would take another step downwards twenty years later.