<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 7 Sep 2017, at 22:02, Itai Ferber &lt;<a href="mailto:iferber@apple.com" class="">iferber@apple.com</a>&gt; wrote:</div><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><div class=""><pre class=" language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(245, 242, 240); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; overflow: auto; padding: 1em; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; text-shadow: white 0px 1px; font-family: 'SF Mono', Menlo, Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; white-space: pre-wrap; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: white 0px 1px; font-family: 'SF Mono', Menlo, Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none;">protocol <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Fooable</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Equatable</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">{ // Equatable is just a simple example</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">var</span> myFoo<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Int</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">{</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">get</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">}</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Fooable</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">static</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">func</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039);">==</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(153, 0, 85);">_</span> lhs<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">Self</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> <span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(153, 0, 85);">_</span> rhs<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">Self</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039);">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039);">&gt;</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Bool</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">{</span>
        <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">return</span> lhs<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span>myFoo <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039);">==</span> rhs<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span>myFoo
    <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">}</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">struct</span> X <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Fooable</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">let</span> myFoo<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Int</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">let</span> myName<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">String</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">// Whoops, forgot to give an implementation of ==</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">}</span>

<span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">print</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">X</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span>myFoo<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(153, 0, 85);">42</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> myName<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token string" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">"Alice"</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039);">==</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">X</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span>myFoo<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(153, 0, 85);">42</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> myName<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token string" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">"Bob"</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">// true</span></code></pre><div class="">This property is<span class="Apple-converted-space">&nbsp;</span><i class="">necessary</i>, but not<span class="Apple-converted-space">&nbsp;</span><i class="">sufficient</i><span class="Apple-converted-space">&nbsp;</span>to provide a correct implementation. A default implementation might be able to<span class="Apple-converted-space">&nbsp;</span><i class="">assume</i>&nbsp;something about the types that it defines, but it does not necessarily know enough.</div></div></div></div></blockquote><div><br class=""></div><div>Sorry but that's a bit of a contrived example; in this case the protocol should <b class="">not</b>&nbsp;implement the equality operator if more information may be required to define equality. It should only be implemented if the protocol is absolutely clear that .myFoo is the only part of a Fooable that can or should be compared as equatable, e.g- if a Fooable is a database record and .myFoo is a primary key, the data could differ but it would still be a reference to the same record.</div><div><br class=""></div><div>To be clear, I'm not arguing that someone can't create a regular default implementation that also makes flawed assumptions, but that synthesised/reflective implementations <b class="">by their&nbsp;very nature have to</b>, as they cannot under every circumstance guarantee correctness when using parts of a concrete type that they know nothing about.</div><br class=""><blockquote type="cite" class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><span style="font-family: SFHello-Regular;" class="">Reflective/synthesised default implementations</span>&nbsp;<b class="" style="font-family: SFHello-Regular;">must by their very nature</b><span style="font-family: SFHello-Regular;" class="">&nbsp;make assumptions about a concrete type that are</span>&nbsp;<b class="" style="font-family: SFHello-Regular;">not</b>&nbsp;<span style="font-family: SFHello-Regular;" class="">cannot be guaranteed to be correct. The properties and methods they may end up interacting with</span><b class="" style="font-family: SFHello-Regular;">may have nothing at all to do with the protocol</b><span style="font-family: SFHello-Regular;" class="">. Equatable remains by far the simplest example; just because a developer has used equatable properties does</span>&nbsp;<b class="" style="font-family: SFHello-Regular;">not</b><span style="font-family: SFHello-Regular;" class="">&nbsp;guarantee that all of them should be compared during a check for equality.</span><br class=""></blockquote><div class="">In the same way that you might consider synthesized conformances to overreach into a type and touch things which are not related to a protocol, default implementations can be considered<span class="Apple-converted-space">&nbsp;</span><i class="">underreach</i>&nbsp;in that they don’t know anything about properties which are necessary for providing a correct implementation.</div></div></blockquote><div><br class=""></div><div>If more information is necessary to provide a correct implementation, then a default implementation shouldn't be provided. This is what unimplemented properties and methods are for; either getting the developer to provide the missing information, or getting them to implement the correct behaviour.</div></div></body></html>