[swift-evolution] [swift-dev] SE-0047 - Defaulting non-Void functions so they warn on unused results

Joe Groff jgroff at apple.com
Mon Oct 31 13:14:44 CDT 2016


> On Oct 30, 2016, at 11:09 AM, Robert Widmann via swift-evolution <swift-evolution at swift.org> wrote:
> 
> If the methods return a reference to self it indicates that you should probably just chain expressions together rather than using a big wall of statements (Smalltalk encourages the same pattern, funnily enough).

Smalltalk specifically has builtin syntax for method cascades, which seem to me like a nicer language-level solution to chaining method calls without requiring them to be manually defined in a "builder pattern" style.

-Joe

> 
> As for the rest, yeah Swift is opinionated.  Every language is opinionated.  We just happen to care about being safe by default.
> 
> ~Robert Widmann
> 
> 2016/10/30 13:52、Jody Schofield <jodyscho at gmail.com> のメッセージ:
> 
>> I think assumptions are being made that shouldn't be. For example I use a lot for design patterns such as the builder. Most of the methods return a reference to self so they can be chained together. The compiler shouldn't tell me I'm wrong for ignoring those return values. It use to be my decision.
>> 
>> Swift was already a very opinionated language and I can see it's being taken even further. A mistake in my opinion and one that is certainly making the language more frustrating than pleasurable to use.
>> 
>> 
>> 
>> On Oct 30, 2016, at 1:32 PM, Robert Widmann <devteam.codafi at gmail.com> wrote:
>> 
>>> Functions that return values return them for a reason.  Ignoring them is, more likely than not, an oversight that should be corrected, hence @discardableResult.  We're talking error codes, object lifetime tokens, failure indicators, etc.  All things that result in ignoring critical code paths for the sake of convenience.  If you find yourself executing a lot of side effects and ignoring return values, I would take a look at why.  A lot of times you have control over the API and can eliminate some of these unused return values.  Otherwise, please try to see if the return values of these functions are relevant to the well-being of your program.
>>> 
>>> ~Robert Widmann
>>> 
>>> 2016/10/30 8:49、Jody Schofield via swift-dev <swift-dev at swift.org> のメッセージ:
>>> 
>>>> Sorry, I'm sure this has been discussed before, but what the heck???
>>>> 
>>>> This feature is killing me. Now I have go add @discardableResult to every function that returns a non-Void or use the ugly syntax `_ =`? 
>>>> 
>>>> Until swift 3 I've really enjoyed the new language. Now I find it to be getting too rigid for the sake of "protecting" me from myself. The safety levels needs to be dialled back some.
>>>> 
>>>> 
>>>> _______________________________________________
>>>> swift-dev mailing list
>>>> swift-dev at swift.org
>>>> https://lists.swift.org/mailman/listinfo/swift-dev
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list