Home > Articles > Software Development & Management

Introduction to Refactoring to Patterns

  • PrintPrint
  • Share ThisShare This
  • DiscussDiscuss
Refactoring to Patterns

This chapter is from the book
Refactoring to Patterns

Refactoring software by hand can be a real pain. So why not just automate the process? In this chapter, Joshua Kerievsky explains the whys and hows of refactoring, and why you shouldn't trust that automated refactoring program.

In this chapter I offer a few thoughts on what refactoring is and what you need to do to be good at it. This chapter is best read in accompaniment with the chapter "Principles in Refactoring" [F].

What Is Refactoring?

A refactoring is a "behavior-preserving transformation" or, as Martin Fowler defines it, "a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior" [F, 53].

The process of refactoring involves the removal of duplication, the simplification of complex logic, and the clarification of unclear code. When you refactor, you relentlessly poke and prod your code to improve its design. Such improvements may involve something as small as changing a variable name or as large as unifying two hierarchies.

To refactor safely, you must either manually test that your changes didn't break anything or run automated tests. You will have more courage to refactor and be more willing to try experimental designs if you can quickly run automated tests to confirm that your code still works.

Refactoring in small steps helps prevent the introduction of defects. Most refactorings take seconds or minutes to perform. Some large refactorings can require a sustained effort for days, weeks, or months until a transformation has been completed. Even such large refactorings are implemented in small steps.

It's best to refactor continuously, rather than in phases. When you see code that needs improvement, improve it. On the other hand, if your manager needs you to finish a feature before a demo that just got scheduled for tomorrow, finish the feature and refactor later. Business is well served by continuous refactoring, yet the practice of refactoring must coexist harmoniously with business priorities.

  • Share ThisShare This
  • Your Account

Discussions

Refactoring and TDD
Posted Aug 10, 2009 03:23 PM by Steve5840
0 Replies

Make a New Comment

You must log in in order to post a comment.

Related Resources

It's Here; Put Away Your Pre-Conceptions on What an OS Must Be: Part III
By John Traenkenschuh on May 27, 2009 No Comments

Having witnessed the PC revolution, Traenk pauses to reflect on the GUI world...

Jim BrosseauRabid Dogma
By Jim Brosseau on February 6, 2009 No Comments

Proposed approaches to building products, software or otherwise, will come and go. One thing that seems to be constant through all this change is that the voice of the latest and greatest is convinced that they have solved the problem once and for all.

Jim BrosseauDon't Spend, Invest
By Jim Brosseau on February 6, 2009 No Comments

There is no shortage of indicators that we are in for in for a rough stretch ahead. While there are some that are still debating whether to call what we are going through a recession or a depression, it is clear to everyone that this is no time for frivolous spending. I would argue that we should always be aware of where we spend our money, and always spend with an understanding of the return we expect.

See All Related Blogs

Informit Network