Agile Glossary

Refactoring

What is Refactoring?

Refactoring consists of improving the internal structure of an existing program’s source code while preserving its external behavior.

The noun “refactoring” refers to one particular behavior-preserving transformation, such as “Extract Method” or “Introduce Parameter.”

Common Pitfalls

Refactoring does “not” mean:

  • rewriting code
  • fixing bugs
  • improve observable aspects of software such as its interface

Refactoring in the absence of safeguards against introducing defects (i.e. violating the “behavior preserving” condition) is risky. Safeguards include aids to regression testing including automated unit tests or automated acceptance tests and aids to formal reasoning such as type systems.

Expected Benefits

The following are claimed benefits of refactoring:

  • refactoring improves objective attributes of code (length, duplication, coupling and cohesion, cyclomatic complexity) that correlate with ease of maintenance
  • refactoring helps code understanding
  • refactoring encourages each developer to think about and understand design decisions, in particular in the context of collective ownership / collective code ownership
  • refactoring favors the emergence of reusable design elements (such as design patterns) and code modules

Signs Of Use

  • version control records (such as CVS or git logs) include entries labeled “Refactoring”
  • the code modifications corresponding to such entries can be verified to be behavior-neutral: no new unit tests or functional tests are introduced, for example

Skill Levels

  • Beginner
  • knows the definition of “refactoring”
  • can use some automated refactorings from the IDE
  • can perform some refactorings by hand
  • is aware of the risks of regression from manual and automated refactorings
  • is aware of code duplication and can remove it by refactoring
  • Intermediate
  • knows and is able to remedy a broader range of “code smells”
  • can chain several refactorings to carry out a design intention, in awareness of the dependencies between refactorings
  • refactors continuously, rather than in sporadic and lengthy sessions
  • Advanced
  • has an acute sense of code duplication and coupling
  • applies refactorings to non-code elements such as database schema, documents, etc.
  • uses refactoring to guide large bodies of code toward design styles intentionally chosen from a broad palette: object-oriented, functional, or inspired by known design patterns

Further Reading

Origins

  • 1984: the notion of “factoring”, anticipation of refactoring, is described in Brodie’s “Thinking Forth”, where it is presented as “organizing code into useful fragments” which “occurs during detailed design and implementation”.
  • 1990: Bill Opdyke coins the term “refactoring” in an ACM SIGPLAN paper with Ralph Johnson, “Refactoring: An aid in designing application frameworks and evolving object-oriented systems”
  • 1992: a comprehensive description of “refactoring” is presented in Opdyke’s thesis, “Refactoring object-oriented frameworks”
  • 1999: the practice of “refactoring”, incorporated a few years earlier into Extreme Programming, is popularized by Martin Fowler’s book of the same name
  • 2001: refactoring “crosses the Rubicon“, an expression of Martin Fowler describing the wide availability of automated aids to refactoring in IDEs for the language Java

Academic Publications

Although the practice of refactoring has become popular, rigorously establishing its benefit in an academic context has proven thorny, illustrating a common gap between research and common practice.

Such studies may be affected by methodological issues, such as identifying what counts as a “refactoring” when examining code histories after the fact; the above paper, for instance, finds that programmers often label “refactorings” sets of code changes which also include additional functionality or bug fixes.

Thank you to our Annual Partners​

Join us today!

Agile Alliance offers many online and in-person events and workshops for our members. If you’re not currently a member, you can join now to take advantage of our many members-only resources and programs.

Get the latest Agile news!

  • This field is for validation purposes and should be left unchanged.

By subscribing, you acknowledge the Agile Alliance Privacy Policy, and agree to receive our emails.

Additional Agile Glossary Terms

In software development, an "estimate" is the evaluation of the effort necessary to carry out a given development task; this is most often expressed in terms of duration.
Continuous Integration is the practice of merging code changes into a shared repository several times a day in order to release a product version at any moment. This requires an integration procedure which is reproducible and automated.
A Niko-niko Calendar is updated daily with each team member's mood for that day. Over time the calendar reveals patterns of change in the moods of the team, or of individual members.
"Information radiator" is the term for any of a number of visual displays which a team places in a highly visible location, so that all team members can see the latest information at a glance.
Scrum is a process framework used to manage product development and other knowledge work. Scrum is empirical in that it provides a means for teams to establish a hypothesis of how they think something works, try it out, reflect on the experience, and make the appropriate adjustments. That is, when the framework is used properly.

Help us keep the definitions updated

Ready to join Agile Alliance?

Unlock members-only access to online learning sessions, Agile resources, annual conference discounts, and more! And when you join, you’ll be supporting our member initiatives, regional events, and global community groups.

Privacy Preference Center

IMPORTANT: We have transitioned to a new membership platform. If you have not already done so, you will need to SET UP AN ACCOUNT on the new platform to establish your user profile. Your previous login credentials will not work until you do this set up.

When you see the login screen, choose “Set up Account” and follow the prompts to create your new account. You can choose to log in using your social credentials for either Google or Linkedin (recommended), or you can set up your account using an email address.