Refactoring is a disciplined technique for restructuring existing source code to improve its internal structure, readability, and maintainability, without changing its external behavior or functionality.1
The key distinction is the preservation of external behavior. The software should do exactly what it did before, but the underlying code should be cleaner, more efficient internally, or easier for future developers to work with. Common examples include renaming a confusing variable, breaking a large function into several smaller ones, or moving a method to a more appropriate class.
Is Just Changing a Description Counted as Refactoring?
No, changing only a description or comment does not count as refactoring in the strict technical sense of the term.
Here is why:
- Refactoring operates on code structure: Refactoring involves changes that affect how the code is organized and executed, even if the end result (the output or behavior) is the same.
- Comments/Descriptions are documentation: Changing descriptions, comments, or documentation is an improvement to the project’s documentation, not a change to the code’s internal structure that is guaranteed to be behavior-preserving.
- No functional change in documentation: The definition of refactoring is that you change the internal code structure without changing the external behavior. A documentation change inherently has no impact on the program’s runtime behavior in the first place.
While improving documentation is valuable and contributes to overall code quality and maintainability (a goal shared with refactoring), it is a separate activity from refactoring the source code itself.2
- https://martinfowler.com/bliki/DefinitionOfRefactoring.html#:~:text=Refactoring%20(noun):%20a%20change,without%20changing%20its%20observable%20behavior. ↩︎
- https://www.emergentsoftware.net/blog/what-is-refactoring/#:~:text=Refactoring%20is%20defined%20as%20the,developer%20to%20understand%20and%20modify. ↩︎
Copied from https://share.google/aimode/TKNxLUYM2BIh7gexP