TechTarget.com/searchapparchitecture

https://www.techtarget.com/searchapparchitecture/definition/refactoring

refactoring

By Alexander S. Gillis

What is refactoring?

Refactoring is the process of restructuring code, while not changing its original functionality. The goal of refactoring is to improve internal code by making many small changes without altering the code's external behavior.

Computer programmers and software developers refactor code to improve the design, structure and implementation of software. Refactoring improves code readability and reduces complexities. Refactoring can also help software developers find bugs or vulnerabilities hidden in their software.

The refactoring process features many small changes to a program's source code. One approach to refactoring, for example, is to improve the structure of source code at one point and then extend the same changes systematically to all applicable references throughout the program. The thought process is that all the small, behavior-preserving changes to a body of code have a cumulative effect. These changes preserve the software's original behavior and do not modify its behavior.

Martin Fowler, considered the father of refactoring, consolidated many best practices from across the software development industry into a specific list of refactorings and described methods to implement them in his book Refactoring: Improving the Design of Existing Code.

What is the purpose of refactoring?

Refactoring improves code by making it:

Code modification is done without changing any functions of the program itself. Many basic editing environments support simple refactorings like renaming a function or variable across an entire code base.

When should code be refactored?

Refactoring can be performed after a product has been deployed, before adding updates and new features to existing code, or as a part of day-to-day programming.

When the process is performed after deployment, it is normally done before developers move on to the next project. An organization may be able to refactor more code at this point in the software delivery lifecycle, where the developers have increased availability and more time to work on the source code changes needed.

A better time to perform refactoring, though, is before adding updates or new features to existing code. When performed at this point, refactoring makes it easier for developers to build onto the existing code because they are going back and simplifying the code, making it easier to read and understand.

When an organization has a strong grasp on the refactoring process, it can make it a regular process. Whenever a developer needs to add something to a code base, they can look at the existing code to see if it is structured in a way that would make the process of adding new code straightforward. If it is not, then the developer can refactor the existing code. Once the new code is added, the developer can refactor the same code again to make it clearer.

What are the benefits of refactoring?

Refactoring can provide the following benefits:

What are the challenges of refactoring?

Challenges do come with the process, however. Some of these include:

Techniques to perform code refactoring

Organizations can use different refactoring techniques in different instances. Some examples include:

Code refactoring best practices

Best practices to follow for refactoring include:

Learn how to refactor code without delaying the deployment process in this article.

15 Sep 2021

All Rights Reserved, Copyright 2019 - 2025, TechTarget | Read our Privacy Statement