[swift-dev] SE-0047 - Defaulting non-Void functions so they warn on unused results

Jody Schofield jodyscho at gmail.com
Tue Nov 1 18:50:29 CDT 2016


I agree that "_ =" is nicer than "(void)".

> Do you find yourself writing a lot of functions that return non-void
results that you frequently want to ignore?  Maybe there's some idiom we
could do a better job of recognizing.

It really depends on the developer. Some will add return values thinking
it's important to and others don't. It certainly is obvious around our use
of the builders and in our unit tests. I'll go back and review the unit
tests, but I think there are enough valid cases where we don't care about
return values if we are spying, mocking, etc.



On Mon, Oct 31, 2016 at 7:14 PM, John McCall <rjmccall at apple.com> wrote:

> On Oct 30, 2016, at 5:49 AM, Jody Schofield via swift-dev <
> swift-dev at swift.org> wrote:
> Sorry, I'm sure this has been discussed before, but what the heck???
>
> This feature is killing me. Now I have go add @discardableResult to every
> function that returns a non-Void or use the ugly syntax `_ =`?
>
> Until swift 3 I've really enjoyed the new language. Now I find it to be
> getting too rigid for the sake of "protecting" me from myself. The safety
> levels needs to be dialled back some.
>
>
> I think we're generally very comfortable with this rule; forgetting to
> handle a return value (maybe because you expect the function to be
> mutating) is a pretty common mistake, and "_ = " seems nicer than the old C
> equivalent "(void)".
>
> Do you find yourself writing a lot of functions that return non-void
> results that you frequently want to ignore?  Maybe there's some idiom we
> could do a better job of recognizing.
>
> John.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20161101/51c75465/attachment.html>


More information about the swift-dev mailing list