Same Method Field Names
ID |
swift.same_method_field_names |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Swift |
Tags |
naming, reliability |
Description
Reports a method and a stored property within the same type whose names
differ only in case (e.g. Count and count). Such pairs confuse
readers and autocompletion — obj.count may resolve to either.
class Account {
var Count: Int = 0 // FLAW
func count() -> Int { 0 } // FLAW
var balance: Double = 0 // OK
}
Rationale
Members whose names differ only in case are a known source of bugs
and slow code review: at the call site obj.count could be either,
depending on the reader’s mental model, and autocompletion offers
both. Swift’s case-sensitive resolution disambiguates them, but the
human reader pays the cost on every visit.
Remediation
Rename one of the members so the lowercased names differ:
class Account {
var totalCount: Int = 0
func currentCount() -> Int { 0 }
}