<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="">+1 for @convenience attached to the return type.</div><div class=""><br class=""></div><div class="">Very, very clean solution.</div><div class=""><br class=""></div><div class="">R+</div><br class=""><div><blockquote type="cite" class=""><div class="">On 25 Feb 2016, at 09:13, Nicola Salmoria 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=""><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=""><div class="">I agree that the attribute should be attached to the return type instead that to the function.</div><div class=""><br class=""></div><div class="">I’d say that the cases where it’s ok to discard the result are when the result is not strictly part of the API, but provided because it could be useful to the caller. An attribute that would naturally describe this could be</div><div class=""><br class=""></div><div class="">@convenience</div><div class=""><br class=""></div><div class="">The first example that comes to mind is Dictionary.updateValue. The declaration could then become</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">mutating</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> updateValue(value: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Value</span>, forKey key: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Key</span>) -> @convenience <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Value</span>?</div></div><div class=""><br class=""></div><div class="">Nicola</div><div class=""><br class=""></div>
> > @optional_result (or ideally @optionalResult if camel-case for attributes is accepted) is clearer I think if we want a shortened two-word form.<br class="">> I don't like "optional" here because it falsely implies a connection with the Optional type.<br class="">> <br class="">> I do think, however, that this needs to be something very short—one or two words, not three or four. One way to trim words would be to attach the attribute to the return type; the position would imply that the keyword related to the return type, so the word "result" would be unnecessary:<br class="">> <br class="">> @ignoreUnusedResult mutating func removeLast() ->Element<br class="">> mutating func removeLast() ->@ignoreUnused Element<br class="">> <br class="">> That might be a little strange, though—we don't currently have any attributes in that position.<br class="">> <br class="">> Another way to make this shorter is to try to find an adjective which implies *why* we can ignore the result—that is, because it isn't important. The problem is that most such adjectives are either compound words:<br class="">> <br class="">> @unimportantResult mutating func removeLast() ->Element<br class="">> mutating func removeLast() ->@unimportant Element<br class="">> <br class="">> @discardableResult mutating func removeLast() ->Element<br class="">> mutating func removeLast() ->@discardable Element<br class="">> <br class="">> Or they're uncommon words people may need to look up:<br class="">> <br class="">> @banalResult mutating func removeLast() ->Element<br class="">> mutating func removeLast() ->@banal Element<br class="">> <br class="">> Actually, I can think of one word in the latter category that many programmers *do* know:<br class="">> <br class="">> @trivialResult mutating func removeLast() ->Element<br class="">> mutating func removeLast() ->@trivial Element<br class="">> <br class="">> --<br class="">> Brent Royal-Gordon<br class="">> Architechies<br class="">> <br class="">> <br class="">> <br class="">><span class="Apple-converted-space"> </span>
</div>_______________________________________________<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></blockquote></div><br class=""></body></html>