Rename Error message methods in Preconditions to describe their action#8490
Open
ArthurVCristiano wants to merge 1 commit into
Open
Rename Error message methods in Preconditions to describe their action#8490ArthurVCristiano wants to merge 1 commit into
ArthurVCristiano wants to merge 1 commit into
Conversation
Member
|
The JDK uses " There may be something that could improve matters here. It's just not immediately crystal clear to me what that should be. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request renames two private methods in
Preconditions.java:badElementIndex()→formatElementIndexMessage()badPositionIndex()→formatPositionIndexMessage()The names
badElementIndexandbadPositionIndexdescribe a situation(a bad index) rather than the action the method performs (formatting an
error message). This violates a fundamental naming convention in Java:
method names should describe what the method does, not the context that
triggered it.
The Guava codebase itself follows this convention consistently across
other utilities. A reader encountering
badElementIndex()must inspectthe implementation to understand that it builds and returns an error
message string — the name alone does not communicate this.
The proposed names
formatElementIndexMessage()andformatPositionIndexMessage()make the intent immediately clear:these methods format a message to be used when an index is invalid.
This change was motivated by an empirical analysis of Google Guava
across 20 releases (v10.0 to v29.0), in which
Rename Methodappearedamong the top 10 most frequent refactoring types detected by
RefactoringMiner. The analysis also showed a consistent growth in WMC
(ρ = +0.818, p < 0.001), indicating that classes have been accumulating
complexity over time. Improving method naming is a low-cost, high-impact
practice to counteract this trend, reducing cognitive overhead for
readers and maintainers.