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

David Owens II david at owensd.io
Wed Mar 2 15:16:31 CST 2016


> On Mar 2, 2016, at 12:20 PM, Erica Sadun <erica at ericasadun.com> wrote:
> 
> This proposal argues that while this workaround makes it clear that the consumption of the result is intentionally discarded, it offers no traceable intent as to whether the API designer meant for this use to be valid.  Forcing an attribute ensures the discardable return value use is one that has been considered and approved by the API author.

But what does this really mean? As an API author, when do I actually mark something as being discardable? Discarding the result is as much about the context in which the API is being used as to the intent the original author had for it.

The only type of API that I can think of where the result is genuinely meant to be discarded are convenience APIs that allow chaining, so `self` is returned.

I find the example of `printf` interesting because the return value for `printf` is used for error handling, so it's essentially an argument that error handling info is fine to mark as discardable. Swift has a very strong statement against that position.

@Tino,

> Functions with side effects: Imho it should be ok to ignore the result

I disagree with this conclusion. Functions that have side effects typically return information regarding the status of the side-effect. Ignoring that is like ignoring error handling information. 

-David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160302/a0192ac9/attachment.html>


More information about the swift-evolution mailing list