It's noticeable that every code example calling isKnownIdentical
given here is followed by ?? false
(assuming I didn't miss one that does otherwise). Are there any cases where the caller would gain anything from the distinction between false
and nil
? Is it just a pointless leaky abstraction?
This analogy came to mind: asking "do we know already the thing is 1 meter long?" and being told "I have no way to know without measuring" (analogous to nil
) compared to "no, I measured it approximately before but not precisely enough to say" (analogous to false
). To both answers, I'd say "dude, just yes or no would have been fine ".
Why isn't yes or no fine for the question isKnownIdentical
?
Unless there's some super-subtle reason a caller would care to distinguish false
and nil
results, then how about just:
public protocol Equatable {
func isKnownIdentical(to other: Self) -> Bool
}
extension Equatable {
func isKnownIdentical(to other: Self) -> Bool { false }
}