[swift-evolution] Make non-void functions @warn_unused_result by default
2th at gmx.de
Wed Mar 2 15:00:13 CST 2016
> This is clearly the case for all “pure” functions (since there are no other side effect, so the result is all the matters)
I think there is little controversy about this: There should never be a reason to call a pure function and ignore its result.
But when a method is designed to have side effects, why should we assume the method isn't called just because of those?
I'm just reading Davids post and thought he already completed the classification, but he focused on another aspect, so here are "my" three groups:
1. Pure function: Ignoring the result is most likely an error
2. Functions with side effects: Imho it should be ok to ignore the result
3. Everything else (getters or other functions that depend on object state that isn't changed by calling the method): Same as pure
So, two out of three groups in favor of "warn_unused_result"… but is this sufficient to make it the default?
"Pure" imho deserves an attribute on its own (its so much nicer than "warn_…" ;-), getters could trigger warnings as well. This leaves a remarkably smaller remainder, and for this group, the current behavior imho is the best choice*:
Warnings shouldn't be used inflationary, and statement that has no issues at all should compile without complains.
I can't remember a single error that happened because I accidentally ignored a result, but I often write functions whose return values are ignored in many cases.
> If no one objects, I'm going to revamp my existing warn_unused_result renaming proposal
* No matter what will be the default, I really think "renaming" is a good idea — and there has been nice suggestions in another thread
More information about the swift-evolution