[swift-evolution] Make non-void functions @warn_unused_result by default
Erica Sadun
erica at ericasadun.com
Wed Mar 2 12:06:03 CST 2016
If no one objects, I'm going to revamp my existing warn_unused_result renaming proposal and transform it into a "make warn_unused_result the default behavior to minimize bugs".
Please let me know asap if anyone else would prefer to get this going.
-- Erica
> On Mar 2, 2016, at 10:51 AM, Gwendal Roué via swift-evolution <swift-evolution at swift.org> wrote:
>
>>
>> Le 2 mars 2016 à 18:45, Chris Lattner <clattner at apple.com> a écrit :
>>
>>> On Mar 2, 2016, at 9:36 AM, Gwendal Roué <gwendal.roue at gmail.com> wrote:
>>>
>>>> The difference between:
>>>> _ = foo()
>>>> and:
>>>> foo()
>>>>
>>>> is that the former expresses that the result is *intentionally* being discarded. The developer obviously thought about it in the first case. In the second case, they may have though about it, or they may not have.
>>>
>>> The former only expresses that the result is *intentionally* being discarded when there is no warning ignoring the returned value.
>>>
>>> As soon as there is a warning ignoring the returned value, as would be the default if the discussed proposal were accepted, people will start writing `_ = …` just to *silence* the warning. Not to express intentional discard. It will be impossible to derive any intention from `_ = …`. There will always be the shadow of a doubt…
>>
>> You’re right that this is possible, but I doubt it is likely. If I wrote this and got a warning:
>>
>> sin(x) // warning, result of call to ‘sin’ is unused
>>
>> it is possible that someone would blithely slap an “_ =“ on the line to silence the warning, but it is much more likely they’d say “whoops, I forgot something”.
>
> Let’s imagine some code that is less implicit:
>
> let _ = cart.remove(item)
>
> What does it mean? Is it that the cart object was badly designed and that the result is an error that we ignore (bad)? Is it that the remove() method returns the removed object, as a confirmation of actual removal, that we ignore here (OK)? What is it? What is it?
>
> Gwendal
>
> _______________________________________________
> 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...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160302/fe09cec6/attachment.html>
More information about the swift-evolution
mailing list