[swift-evolution] Make non-void functions @warn_unused_result by default
Gwendal Roué
gwendal.roue at gmail.com
Wed Mar 2 11:58:53 CST 2016
> 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 reason why I think it is important is that many Swift libraries are shipping, and will ship. Their quality will vary.
Some may use some odd pattern like not throwing errors but returning error codes instead (look at the SQLite Swift wrappers landscape, it’s full of this).
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.
Gwendal
More information about the swift-evolution
mailing list