<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="">There are plenty of APIs that return an opaque object, like a token, that isn’t always needed. Consider NSNotificationCenter’s <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="">) </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 <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="">) </span>with it.<div class=""><br class=""><div class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); 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-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; " class=""><div style="color: rgb(0, 0, 0); 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-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; " class=""><div style="color: rgb(0, 0, 0); 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-size-adjust: auto; -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> | <a href="https://twitter.com/SlaunchaMan" class="">@SlaunchaMan</a> | <a href="http://jeffkelley.org" class="">jeffkelley.org</a></div></div></span></div></div></div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Mar 2, 2016, at 4:21 PM, David Owens II via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Swift's error handling model is optional -> throws -> 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 <<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>> wrote:<br class=""><br class="">On Wed, Mar 2, 2016 at 1:16 PM, David Owens II via swift-evolution<br class=""><<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><blockquote type="cite" class=""><br class="">On Mar 2, 2016, at 12:20 PM, Erica Sadun <<a href="mailto:erica@ericasadun.com" class="">erica@ericasadun.com</a>> 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<i;j++){if(!(i%j)){j=0;break;}}if<br class="">(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>>*/<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="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></div></blockquote></div><br class=""></div></div></body></html>