[swift-evolution] [Review] SE-0185 - Synthesizing Equatable and Hashable conformance
swift-evolution at haravikk.me
Thu Aug 10 04:07:42 CDT 2017
> On 10 Aug 2017, at 00:08, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
> • What is your evaluation of the proposal?
Generally positive, but I don't feel that conforming to Equatable/Hashable is sufficient as an opt-in. Consider for example someone who declares their type as Equatable/Hashable, then sets to work on the details of their type, forgetting to implement the actual equatable/hashable behaviour they want.
I would suggest either that there be a keyword/attribute to indicate when the synthesised solution be used, or that there be alternate protocols such as AutoEquatable and AutoHashable; the idea being that the more explicit declaration results in the synthesised behaviour, or produces errors if it isn't possible or if a custom implementation is provided. An advantage of these methods is that the synthesis could potentially then be allowed for extensions (unless there's some other reason they aren't?), since they're absolutely explicit in what they want.
I'm just wary of these being implemented automatically cases where someone forgets to do it themselves, or if they accidentally define the requirements incorrectly (e.g- they provide a hash_value property instead of hashValue). I think for this to count as opt-in behaviour the developer should be specifically opting in to synthesised implementations, rather than just declaring conformance as normal and having it kick-in in certain circumstances.
> • Is the problem being addressed significant enough to warrant a change to Swift?
While it's a somewhat minor problem, it does commonly involve a lot of boiler-plate where it can also be easy to introduce mistakes. So I do feel a change is warranted.
> • Does this proposal fit well with the feel and direction of Swift?
Other than the means of opting in I'd say so, yes.
> • How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
Quick re-read of the proposal, otherwise been following discussion for a while.
More information about the swift-evolution