[swift-evolution] [Proposal] Explicit Synthetic Behaviour
David Waite
david at alkaline-solutions.com
Tue Sep 12 16:57:22 CDT 2017
> On Sep 12, 2017, at 11:00 AM, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
>
> Suppose instead this were about a protocol named Fooable and a requirement called foo() that has a default implementation. Everything you just talked about would apply equally. Am I to understand that you are opposed to default implementations in general? If so, then that’s got nothing to do with synthesized Equatable conformance. If not, then you’ll have to justify why.
First - I can go either way on this issue, since proper traits/mixins and hygienic macros both appear to be strong influencers which will drive evolution in ways we cannot evaluate yet.
In my opinion, the difference between most protocol default implementations and Equatable/Hashable is that most protocol default implementations are based on the contract of the protocol itself. I can understand that Sequence#contains works by default because a Sequence implementation has a required makeIterator() function that meet the Sequence contract (and returns an Iterator that meets the iterator contract).
There is nothing in the Equatable contract saying "two instances of a type are considered Equatable for value types when all the properties on the type are Equatable and compare as being equal." That is a behavioral assumption made by the default implementation.
The current usage of traits in swift (in my experience) can be a bit deficient in that there is an assumption of a single behavior. For example - I might be able to default quite a bit of a view's delegate if I was willing to make assumptions, such as each row being a fixed size with a fixed (set of) views. But this is inappropriate as a default behavior for all table view delegates.
We also have the disadvantage that we haven't solved the problem of indicating a method is meant to implement a protocol, so typos and incorrect function signatures can result in the wrong behavior at runtime.
-DW
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170912/b1ecc850/attachment.html>
More information about the swift-evolution
mailing list