[swift-evolution] Make non-void functions @warn_unused_result by default
fred.kl at me.com
Thu Dec 10 17:39:50 CST 2015
I’m in favor of this change, and I would rather see this go the route of an ‘@suppress_unused_result' attribute.
I’m in agreement that it makes sense to let the designer of the API determine whether they want to let people ignore the return value. Ignoring the return value need not be made explicit at the point of use with `let _ = …` if it is already established in the documentation that the return value may not need to be used.
> On Dec 10, 2015, at 6:30 PM, Adrian Kashivskyy via swift-evolution <swift-evolution at swift.org> wrote:
> Matthew, I actually like your idea better than using an opposite "@suppress_unused_result" attribute. In addition, it will even be easier to implement, since "let _" syntax is already supported in the language.
> Pozdrawiam – Regards,
> Adrian Kashivskyy
>> Wiadomość napisana przez Matthew Johnson <matthew at anandabits.com <mailto:matthew at anandabits.com>> w dniu 11.12.2015, o godz. 00:28:
>> Why should unused results be acceptable? Why not require callers to explicitly throw away the result:
>> let _ = funcReturningValueThatIsIgnored()
>> Yes this is extra syntax, but it also makes it clear that the value was intended to be ignored and the function was only executed for side-effects.
>>> On Dec 10, 2015, at 5:23 PM, Guillaume Lessard via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>> On 10 déc. 2015, at 15:58, Adrian Kashivskyy via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>> I think non-void functions should warn about their return value being unused by default, thus eliminating the need to attribute them with @warn_unused_result.
>>> I strongly don’t like this idea. This being said, if it happens ann attribute that says "unused result are acceptable" must be created. Makes me wince.
>>> Guillaume Lessard
>>> swift-evolution mailing list
>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution