[swift-evolution] Make non-void functions @warn_unused_result by default

Stephen Celis stephen.celis at gmail.com
Wed Mar 2 12:32:55 CST 2016

> On Mar 2, 2016, at 12:51 PM, Gwendal Roué via swift-evolution <swift-evolution at swift.org> wrote:
> 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?

The fact that `_ =` prompts these questions is a good thing, in my opinion.

> Some may import some foreign (yet valid) patterns like having the remove() function of a collection return the removed element (I didn’t have to look too far way: here is a lib with much hype theses days which does exactly that: https://github.com/lorentey/BTree/blob/master/Sources/BTree.swift#L507)
> See?
> With the new default, we have a real risk of indecipherable `let _ = …` surging here and there and everywhere. Just because developers will want to silence those unwanted warnings.

Libraries with such behaviors would be free to design their API to suppress these warnings. The "risk" of `_ =` is reward: it's a loud signal that developers can't really ignore.

(Also, a little reminder: you can write `_ =` and avoid the `let`.)


More information about the swift-evolution mailing list