<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=""><div>Thanks very much for the quick feedback TJ,&nbsp;</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Dec 17, 2015, at 5:52 PM, T.J. Usiyan &lt;<a href="mailto:griotspeak@gmail.com" class="">griotspeak@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hello Dave,<div class=""><br class=""></div><div class="">I like this change and think that it will help clarify the purpose of the type. As I was reading, the only concern that I had was the name. Could you please provide some of the names that you all have considered </div></div></div></blockquote><div><br class=""></div>Honestly, I am sorry to say, we did that exercise almost a month ago and I don’t remember the ones we discussed.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">so that we can avoid suggesting the same things? My suggestion is&nbsp;</div><div class=""><br class=""></div><div class=""><div style="font-size:13px" class="">&nbsp; &nbsp;&nbsp;<font face="Menlo" class="">CF<i class="">Something</i>(<i class="">arguments…</i>).retainedObject() // when the result is returned at +1</font></div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class="">or</div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class="">&nbsp; &nbsp;&nbsp;<font face="Menlo" class="">CF<i class="">Something</i>(<i class="">arguments…</i>).unretainedObject() &nbsp; &nbsp;// when the result is returned at +0</font></div></div><div style="font-size:13px" class=""><font face="Menlo" class=""><br class=""></font></div>on the premise that the important bit of information is whether or not the object is already retained. No matter what names are chosen, that is the data which determines which method to call. `retainedObject | unretainedObject`, `takeRetainedObject | takeUnretainedObject`, or &nbsp;`retained | unretained` all seem like viable options (that you have probably considered).</div></div></blockquote><div><br class=""></div><div><br class=""></div>Some issues with these names:</div><div><br class=""></div><div><ul class="MailOutline"><li class="">The&nbsp;<a href="https://swift.org/documentation/api-design-guidelines.html#be-grammatical" class="">“ed/ing” rule</a>&nbsp;makes these names suggest that the accessors are idempotent, but the first one must be called exactly once. &nbsp;That name should really be an active verb since it is state-changing.</li><li class="">“retainedObject” also suggests that it’s returning some underlying object after retaining it, which is almost the opposite of what that API does… and vice-versa for “unretainedObject"</li><li class="">Also, the object “has been retained” in all cases, or it would have been deallocated. &nbsp;The question is whether the object would leak if we fail to call release on it</li><li class="">Nothing in these names connect them to what the documentation says about the functions that return Unmanaged, so it’s hard to know which one to call</li><li class="">The second API is objectively safer than the first one (which causes undefined behavior when overused and only leaks when underused). &nbsp;The API I proposed makes it clear that they are not peers, where yours implies parity—though I am of two minds about the value of representing the lack of parity.</li></ul></div><div><br class=""></div><div>You may legitimately argue that any of these concerns are unimportant, but those are the ones that come up for me.</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class="">TJ</div><div class=""><br class=""></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Dec 17, 2015 at 8:37 PM, Dave Abrahams via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">Hi Everybody,</div><div class=""><br class=""></div><div class="">We’ve been working on a rewrite of the Unmanaged&lt;T&gt; component, and are soliciting comments.&nbsp; First, a little background:</div><div class=""><br class=""></div><div class=""><ul class=""><li class=""><a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/WorkingWithCocoaDataTypes.html#//apple_ref/doc/uid/TP40014216-CH6-ID79" target="_blank" class="">Unmanaged</a>&nbsp;is primarily used as a return type from imported CoreFoundation functions that haven’t been annotated with reference-counting semantic information</li><li class="">A secondary known use-case is as a vehicle for creating a COpaquePointer containing a reference’s bits, e.g. for when you need to pass a reference through C APIs that use “void*” as a universal “give me some info and I’ll give it back to your callback” mechanism.</li></ul><div class=""><br class=""></div><ul class=""><li class="">We saw several problems with Unmanaged that we wanted to fix:</li><ul class=""><li class="">It was poorly-named (the reference is managed by <i class="">somebody</i>, we just aren't representing that management in the type system).</li><li class="">Its interface was much broader than it needs to be to cover the use-cases</li><li class="">The purpose of many of its APIs was unclear</li><li class="">Its documentation was vague and hard to understand.</li><li class="">It didn’t establish a maximally-safe usage pattern for handling the results of un-annotated CoreFoundation functions.</li></ul></ul></div><div class=""><br class=""></div><div class="">The code for the proposed replacement, called UnsafeReference, is&nbsp;<a href="https://github.com/dabrahams/swift/blob/6eb86b48d150342709da3f3be9c738df23382866/stdlib/public/core/UnsafeReference.swift" target="_blank" class="">here</a>, and a commit that updates Swift to use it is&nbsp;<a href="https://github.com/dabrahams/swift/commit/6eb86b48d150342709da3f3be9c738df23382866" target="_blank" class="">here</a>.&nbsp;</div><div class=""><br class=""></div><div class=""><font size="5" class="">Maximally Safe Usage</font></div><div class=""><br class=""></div><div class="">The recommended usage pattern for handling an <font face="Menlo" class="">UnsafeReference&lt;T&gt;</font> returned by a function <font face="Menlo" class="">CF<i class="">Something</i></font> is to always use the <font face="Menlo" class="">T</font> instance produced by one of the forms:</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; <font face="Menlo" class="">CF<i class="">Something</i>(<i class="">arguments…</i>).release() // when the result is returned at +1</font></div><div class=""><br class=""></div><div class="">or</div><div class=""><br class=""></div><div class=""><div class="">&nbsp; &nbsp; <font face="Menlo" class="">CF<i class="">Something</i>(<i class="">arguments…</i>).object &nbsp; &nbsp;// when the result is returned at +0</font></div></div><div class=""><br class=""></div><div class="">In other words, turn the&nbsp;<span style="font-family:Menlo" class="">UnsafeReference&lt;T&gt;</span>&nbsp;into a safe&nbsp;<span style="font-family:Menlo" class="">T</span>&nbsp;as quickly as possible, and never store the <span style="font-family:Menlo" class="">UnsafeReference&lt;T&gt;</span>&nbsp;in a variable so that it can’t be (mis)used thereafter.</div><div class=""><br class=""></div><div class=""><div class=""><font size="5" class="">Points of Discussion</font></div></div><div class=""><br class=""></div><div class="">We’re interested in any feedback you might have, but there are a few points we’d especially like to address:</div><div class=""><br class=""></div><div class=""><ul class=""><li class="">The name of the <font face="Menlo" class="">release()</font> method has been contentious.</li><ul class=""><li class="">👍: Documentation—or naming conventions such as the “<a href="https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html" target="_blank" class="">create rule</a>”—normally says something like “you are responsible for releasing the result” in those cases where <font face="Menlo" class="">release()</font> must be called, so there’s a very direct way to know which variant of the recommended usage pattern to employ.</li><li class="">👎: Some people who are very familiar with existing manual retain/release programming find the&nbsp;recommended usage pattern really counter-intuitive because they're “using something after calling release on it,” which one never does in Objective-C.</li><li class="">The alternative names we’ve been able to think of so far are verbose, clumsy, and don’t match up with anything in the documentation of the called function, so this seems like a really hard naming problem.&nbsp; Better ideas from the community would be most welcome here.</li></ul><li class="">We’re not sure about the&nbsp;<a href="https://github.com/dabrahams/swift/blob/6eb86b48d150342709da3f3be9c738df23382866/stdlib/public/core/UnsafeReference.swift#L27" target="_blank" class="">terminology</a>&nbsp;(Unretained/Retained/Released)&nbsp;used to precisely describe the semantics of <font face="Menlo" class="">UnsafeReference</font>. We’d like to know if these terms make sense to you or whether you have better ideas.</li><li class="">We want to know whether the usage pattern recommended above works for you.</li><li class="">We want to know if the API is sufficiently broad or if there are things you currently get—and need—from <font face="Menlo" class="">Unmanaged</font> that we’ve left out.</li></ul></div><div class=""><br class=""></div><div class="">Thanks in advance,</div><div class=""><br class=""></div><div class=""><div class="">
-Dave<div class=""><br class=""></div><br class="">

</div>
<br class=""></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=3FGfocPbgxkNkmje7djckg9Iw-2BGYY3X6RxJ1tkUXKCqykc-2FqvD6RA4Kk-2FqmXE0Z5aP9e7T8v6GNiR4gmT-2Bsb2uF-2F-2Bjnpc6za8Ziq0Ab54tqerszr6L6jONxR9lePuurF73ErW2FlVUsavvg650rR01qquqQ-2BPSKy9mQhdPVlp5R5P-2FYV5LfMSxcKV-2F2LQsjudDhAsZQswduZViik6Epfu8NUpbkQ-2B3ewHkCNsa-2FWTrM-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important" class="">
</div>
<br class="">_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""><div class="">
-Dave<div class=""><br class=""></div><br class="Apple-interchange-newline">

</div>
<br class=""></body></html>