[swift-evolution] Make non-void functions @warn_unused_result by default
David Owens II
david at owensd.io
Wed Mar 2 15:21:38 CST 2016
Swift's error handling model is optional -> throws -> runtime error. Returning a result is perfectly acceptable as a return value.
And what information are you returning from your side-effect methods that you shouldn't be using? That's what I'm having a hard time trying to grok - the actual use case.
-David
> On Mar 2, 2016, at 1:18 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
>
> 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