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

Dmitri Gribenko gribozavr at gmail.com
Wed Mar 2 15:18:07 CST 2016


On Wed, Mar 2, 2016 at 1:16 PM, David Owens II via swift-evolution
<swift-evolution at swift.org> wrote:
>
> 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.

When it makes sense to call your method just for side-effects.

If you have error handling information, use 'throw', don't use return values.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list