Beklager, indholdet på denne side er ikke tilgængeligt på dit valgte sprog.

Spring til hovedindholdet

Startside Refactoring

Refactoring

(Also code refactoring)

Refactoring definition

Refactoring, also known as code refactoring, is the process of restructuring existing code without changing or impacting its functionality and behavior. Refactoring can help improve the code’s internal structure, design, and implementation. Meanwhile, the input and output results remain unchanged.

Refactoring aims to:

  • Improve the code’s readability and simplify its logic.
  • Improve maintainability and make it easier to update in the future.
  • Eliminate bad practices and errors to reduce the likelihood of malfunction.
  • Improve performance without causing disruption.
  • Reduce technical debt while maintaining functionality.

The goal of refactoring is to improve the code’s quality. While new features might be implemented during the process, it’s not a priority. Refactoring is usually done in small steps to ensure the restructured code works as intended.

See also: code bloat, code management, code morphing, pseudocode

Code refactoring techniques

  • Red-green testing: The code is tested for errors (red light) until it passes (green light).
    Extract method/function. Break large functions into smaller ones
  • Renaming: Names used in the code are updated to be clearer and more descriptive.
  • Duplication removal: Unnecessary code repetitions are deleted without impacting its functionality.
  • Simplification: Parts of the code are changed to follow simpler structures.
  • Reorganization: Parts of the code are moved to other locations.