<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br><br>Sent from my iPad</div><div><br>On Dec 31, 2015, at 10:09 AM, Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com">dabrahams@apple.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div class="">
<div class="">-Dave</div>

</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Dec 31, 2015, at 7:33 AM, Matthew Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: AvenirNext-Medium; font-size: 15px; 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=""><div class=""><br class="Apple-interchange-newline">On Dec 31, 2015, at 5:04 AM, Tino Heth &lt;<a href="mailto:2th@gmx.de" class="">2th@gmx.de</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><blockquote type="cite" class="">I don’t want this thread to get distracted with memberwise initialization<br class=""></blockquote>Makes sense in general, but Kotlin solves those problems as a whole, and the major benefit of their approach is that everything fits together really fine.<br class="">But I'll skip everything that is not related to forwarding.<br class=""><br class=""><blockquote type="cite" class="">One approach I considered would look like this:<br class=""><br class="">class Forwarder: P {<br class="">&nbsp;&nbsp;&nbsp;// I didn’t like `implements` but didn’t have a better idea before I abandoned this approach<br class="">&nbsp;&nbsp;&nbsp;var forwardee: Forwardee implements P<span class="Apple-converted-space">&nbsp;</span><br class="">}<br class=""></blockquote>Honestly, I'm can't see the value this discarded variant has for this discussion… you have to pit your proposal against Kotlin if you really want to convince anyone of its superiority.</div></div></blockquote><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">With the memberwise initialization proposal you also have the initializer synthesized automatically. &nbsp;The only thing it doesn’t do that your Kotlin example does is automatically declare conformance. &nbsp;This was an intentional design decision because it allows for additional expressivity. &nbsp;This is addressed in the alternatives considered section of the proposal. &nbsp;<br class=""></blockquote>Can you be more precise? Kotlin clearly states what a class is doing in its first line, with all expressivity that is necessary by practical means.<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">What I mean is this. &nbsp;In the example you gave and the syntax Kotlin uses:</div><div class=""><br class=""></div><div class="">classs Forwarder(forwardee: Forwardee):<span class="Apple-converted-space">&nbsp;</span><b class="">P by forwardee</b><span class="Apple-converted-space">&nbsp;</span>{}</div><div class=""><br class=""></div><div class="">Forwarding is coupled to protocol conformance. &nbsp;This means I cannot use forwarding without conforming to the protocol that is forwarded. &nbsp;</div><div class=""><br class=""></div><div class="">Here is a quick example using the syntax of my proposal to demonstrate the difference:</div><div class=""><br class=""></div><div class="">class Forwarder {</div><div class="">&nbsp; let forwardee: Forwardee</div><div class="">&nbsp; forward P to forwardee</div><div class="">}</div><div class=""><br class=""></div><div class="">vs</div><div class=""><br class=""></div><div class=""><div class="">class Forwarder: P {</div><div class="">&nbsp; let forwardee: Forwardee</div><div class="">&nbsp; forward P to forwardee</div><div class="">}</div></div><div class=""><br class=""></div><div class="">In the first example Forwarder does not conform to P. &nbsp;Forwarding is only used to synthesize the members of P. &nbsp;I am greatly expanding the motivation section of the proposal and will have examples showing where this is what you want. &nbsp;The lazy collections section I posted last night includes the first examples where this is the case.</div><div class=""><br class=""></div><div class="">In the second example here Forwarder does conform to P. &nbsp;The author of Forwarder has the flexibility to specify whether conformance is desired or not.</div></div></div></blockquote><div><br class=""></div>There are ways to handle that, including factoring the APIs of interest out of P and into a private protocol Q, then declaring the Forwardee’s conformance to Q. &nbsp;Now, there’s an expressivity problem with our current access control system that you can’t use an internal or private protocol to provide public API, but that should be fixed separately.</div></div></blockquote><div><br></div>I'm not sure where Q comes into play in this specific example. &nbsp;The idea here is that forwarding implementations of all members of P are synthesized by the forward declaration. &nbsp;It is left up to Forwarder to decide whether or not to declare actual conformance to P. &nbsp;I am also confused by "<span style="background-color: rgba(255, 255, 255, 0);">then declaring the Forwardee’s conformance to Q" because we are discussing <b>Forwarder's&nbsp;</b>conformance here, not&nbsp;<b>Forwardee’s.</b></span><div><br></div><div>What do you have in mind when you mention using a private or internal protocol to provide public API? &nbsp;It sounds like that might be interesting but I'm having trouble imagining what the syntax would look like and exactly how it would work. &nbsp;Is this something that is planned? &nbsp;What might it look like?</div><div><br></div><div>In any case, I don't see why that is related to requiring a Forwarder to conform to the forwarded protocol. &nbsp;There doesn't appear to me to be a good reason to require that and there are reasons not to require it. &nbsp;Protocols enable and drive the forwarding member synthesis mechanism but that mechanism doesn't need to require or provide conformance. &nbsp;It is a third major way to use protocols in addition to generic constraints and existential types.</div><div><div><br><blockquote type="cite"><div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div style="font-family: AvenirNext-Medium; font-size: 15px; 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=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">Another difference that is maybe subtle but I think important is that with the approach I considered forwarding is declared in the body of a type or extension which emphasizes the fact that forwarding is an implementation detail, not something users of the type should be concerned with.<br class=""></blockquote>But what is the benefit of this emphasis? No solution requires to make the details visible in the public interface, and the ability to bury an important thing like protocol conformance somewhere in the class implementation is no advantage for me.<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">Protocol conformance is not buried in the implementation in my solution. &nbsp;I hope the previous example makes that clear. &nbsp;What<span class="Apple-converted-space">&nbsp;</span><b class="">is</b>&nbsp;buried in the implementation is the forwarding declaration which causes the compiler to synthesize forwarding member implementations. &nbsp;This synthesis is an implementation detail and should<span class="Apple-converted-space">&nbsp;</span><b class="">not</b>&nbsp;be visible outside the implementation.</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">This approach was abandoned as it leads to problems in expressivity and clarity. &nbsp;Please see alternatives considered for an elaboration of that. &nbsp;This is especially true with the new approach to handling Self values that Brent suggested. &nbsp;That approach requires additional syntax around the forwarding declaration, but adds both clarity and expressiveness.<br class=""></blockquote>I think there is little need to worry about expressiveness for a feature that most potential users will probably never utilize in real code — and I don't think options like not conforming to a protocol that is forwarded is a big win here. It looks to me like you are optimizing for very uncommon cases, and sacrificing ease of use in the situations that are the most common by far.<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">Like I stated, I am working on adding several examples of how this feature can be used in real code. &nbsp;Please have a look at the lazy collections example I shared last night. &nbsp;This example, as well as at least one other coming examples take advantage of the ability to use forwarding without requiring conformance.</div><div class=""><br class=""></div><div class="">As with the memberwise initialization proposal, the syntax you would like to see can easily be added as syntactic sugar on top of the current proposal. &nbsp;I would not support that as I do not like the syntax Kotlin uses for reasons already stated, but that shouldn’t stop you from pursuing a proposal for it. &nbsp;Maybe a lot of people would agree with you and it would be accepted.</div><div class=""><br class=""></div><div class="">Matthew</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">It appears to me that you value conciseness very highly. &nbsp;I do value conciseness but I also value safety, clarity, and expressiveness. &nbsp;<br class=""></blockquote>No, I value elegance and simplicity &nbsp;— they often lead to clarity and safety.<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">Why not simply make this feature syntactic sugar and just auto-generate the forwarding methods?<br class=""></blockquote><br class="">That is exactly what this proposal does. &nbsp;Why do you feel it is not doing that?<br class=""></blockquote>you're right, guess I mixed up the proposal with something else; so at least we agree on how it should work ;-)<br class=""><br class="">I'm not saying Swift has to copy another language, but I doubt that anyone who knows Kotlin would actually consider to drop their solution in favor of what is currently discussed...<br class=""><br class="">Tino<br class=""><br class=""></div></div></blockquote></div><br class="" style="font-family: AvenirNext-Medium; font-size: 15px; 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;"><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=JfMPa-2F7wwZPzsZ3QKA8NjtONIYX4SjbWuUxtpfsTY2jc73j3MLQkAv6HwzbAdik0iwLTTmL7so7Q2VgA-2B5CYwXXQ2iMcbHrhe71klOSbLwbBJQrEqzBoEd0ez-2FQRFJ3tZfNVx-2FYIsHEN3Q28AGznhpuMDhjO-2BP76umICzJX0uNq3rMCwM92VLkDUCEyAPgdC0BOpBBPLthrf2-2BfeMt6uCMMluHR79Fk5R6w7S3Zfvf4-3D" alt="" width="1" height="1" border="0" style="font-family: AvenirNext-Medium; font-size: 15px; 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; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: AvenirNext-Medium; font-size: 15px; 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; float: none; display: inline !important;" class=""><span class="Apple-converted-space">&nbsp;</span></span><span style="font-family: AvenirNext-Medium; font-size: 15px; 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; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: AvenirNext-Medium; font-size: 15px; 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=""><span style="font-family: AvenirNext-Medium; font-size: 15px; 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; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: AvenirNext-Medium; font-size: 15px; 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=""><a href="mailto:swift-evolution@swift.org" style="font-family: AvenirNext-Medium; font-size: 15px; 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="">swift-evolution@swift.org</a><br style="font-family: AvenirNext-Medium; font-size: 15px; 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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: AvenirNext-Medium; font-size: 15px; 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="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div></blockquote></div></div></body></html>