<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 class="">Sure, but the token is intended to be used, that's why the API author returned it. What's the rationale you give to an API author on why would I mark that as discardable?</div><div class=""><br class=""></div><div class="">You gave two contexts in which the result can either be discarded or should be kept. How does the API author know which context you are using? How does the compiler?</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Menlo" class="">let _ = NSNotificationCenter.defaultCenter.addObserverForName(...)</font></div></blockquote><div class=""><br class=""></div><div class="">vs.&nbsp;</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><font face="Menlo" class="">NSNotificationCenter.defaultCenter.addObserverForName(...)</font></div></div></blockquote><div class=""><br class=""></div><div class="">The first version is explicitly saying, "yes, I know the API author is given me back something I may need but I know I don't".&nbsp;</div><div class="">The second version isn't saying anything about the return value.</div><div class=""><br class=""></div><div class="">Had the API been marked as discardable, there's no way to tell if you've made an oversight error or were being explicit about not needing the result.</div><div class=""><br class=""></div><div class="">-David</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Mar 2, 2016, at 1:25 PM, Jeff Kelley &lt;<a href="mailto:slaunchaman@gmail.com" class="">slaunchaman@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">There are plenty of APIs that return an opaque object, like a token, that isn’t always needed. Consider NSNotificationCenter’s&nbsp;<span class="nl" style="border: 0px; font-size: 12px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace;">addObserverForName</span><span style="font-family: Menlo, monospace; font-size: 12px; background-color: rgb(255, 255, 255);" class="">(</span><span class="nl" style="border: 0px; font-size: 12px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace;">_</span><span style="font-family: Menlo, monospace; font-size: 12px; background-color: rgb(255, 255, 255);" class="">:</span><span class="nl" style="border: 0px; font-size: 12px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace;">object</span><span style="font-family: Menlo, monospace; font-size: 12px; background-color: rgb(255, 255, 255);" class="">:</span><span class="nl" style="border: 0px; font-size: 12px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace;">queue</span><span style="font-family: Menlo, monospace; font-size: 12px; background-color: rgb(255, 255, 255);" class="">:</span><span class="nl" style="border: 0px; font-size: 12px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace;">usingBlock:</span><span style="font-family: Menlo, monospace; font-size: 12px; background-color: rgb(255, 255, 255);" class="">)&nbsp;</span>method; it returns an opaque NSObject to act as the observer. If you’re adding an observer that lasts the lifetime of your application, you may not need to do anything with the observer, and so you might not use the return value. Other times, for short-lived observers, you’d save that reference so you could call&nbsp;<span class="nl" style="border: 0px; font-size: 12px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace;">removeObserver</span><span style="font-family: Menlo, monospace; font-size: 12px; background-color: rgb(255, 255, 255);" class="">(</span><span class="nl" style="border: 0px; font-size: 12px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace;">_</span><span style="font-family: Menlo, monospace; font-size: 12px; background-color: rgb(255, 255, 255);" class="">:</span><span style="font-family: Menlo, monospace; font-size: 12px; background-color: rgb(255, 255, 255);" class="">)&nbsp;</span>with it.<div class=""><br class=""><div class=""><br class=""><div class="">
<div style="font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; line-height: normal; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; " class=""><div class="">Jeff Kelley</div><div class=""><br class=""></div><div class=""><a href="mailto:SlaunchaMan@gmail.com" class="">SlaunchaMan@gmail.com</a>&nbsp;|&nbsp;<a href="https://twitter.com/SlaunchaMan" class="">@SlaunchaMan</a>&nbsp;|&nbsp;<a href="http://jeffkelley.org/" class="">jeffkelley.org</a></div></div></span></div></div></div>
</div>
<br class=""><div class=""><blockquote type="cite" class=""><div class="">On Mar 2, 2016, at 4:21 PM, David Owens II 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 class="">Swift's error handling model is optional -&gt; throws -&gt; runtime error. Returning a result is perfectly acceptable as a return value.<br class=""><br class="">And what information are you returning from your side-effect methods that you shouldn't be using? That's what I'm having a hard time trying to grok - the actual use case.<br class=""><br class="">-David<br class=""><br class=""><blockquote type="cite" class="">On Mar 2, 2016, at 1:18 PM, Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>&gt; wrote:<br class=""><br class="">On Wed, Mar 2, 2016 at 1:16 PM, David Owens II via swift-evolution<br class="">&lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><blockquote type="cite" class=""><br class="">On Mar 2, 2016, at 12:20 PM, Erica Sadun &lt;<a href="mailto:erica@ericasadun.com" class="">erica@ericasadun.com</a>&gt; wrote:<br class=""><br class="">This proposal argues that while this workaround makes it clear that the<br class="">consumption of the result is intentionally discarded, it offers no traceable<br class="">intent as to whether the API designer meant for this use to be valid.<br class="">Forcing an attribute ensures the discardable return value use is one that<br class="">has been considered and approved by the API author.<br class=""><br class=""><br class="">But what does this really mean? As an API author, when do I actually mark<br class="">something as being discardable? Discarding the result is as much about the<br class="">context in which the API is being used as to the intent the original author<br class="">had for it.<br class=""></blockquote><br class="">When it makes sense to call your method just for side-effects.<br class=""><br class="">If you have error handling information, use 'throw', don't use return values.<br class=""><br class="">Dmitri<br class=""><br class="">-- <br class="">main(i,j){for(i=2;;i++){for(j=2;j&lt;i;j++){if(!(i%j)){j=0;break;}}if<br class="">(j){printf("%d\n",i);}}} /*Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>&gt;*/<br class=""></blockquote><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" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""></body></html>