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

Davide De Franceschi defrenz98 at hotmail.com
Wed Mar 2 08:30:51 CST 2016


I think you might have overseen one _big_ point in all of this though.

If `@warn_unused_result` becomes a default for functions returning non-Void, then there's a _really_ easy way to explicitly discard the result:

`_ = myNonVoidFunc()`

> Cc:swift-evolution<swift-evolution at swift.org>
> Subject:[swift-evolution] Make non-void functions @warn_unused_result y default
> Date:2 March 2016 at 12:20:58 GMT
> 
> 
> 
> > Macho posturing about how only bad programmers need safety is not helpful
> I'm not arguing against safety at all — but safeguards sacrificing ease of use often open a new can of worms.
> Swift is already quite "mothering" with its warnings, and I'd rather move some checks to a separate analyze-step than adding new ones (one example are the hints to replace "var" with "let", which are a constant distraction until I finally write the line with the change…)
> It is fine to throw a warning for pure functions, and it is good practice to annotate methods that can be misinterpreted easily, but I'd rather trust in the developer discarding a result in most other situations.
> The compiler can't know wether a method was called for its side effects, so I prefer to leave this decision to the human using it — he should know.
> 
> You may code in a different style as Andrey and I, but discardable return values are no anti-pattern, so I don't think they should be punished with a monstrosity like "@dont_warn_unused_result" (shiver).
> 
> - Tino
> 
> I myself break the most prominent programmer cliches easily (including the ability to cook quiche that has never seen a freezer ;-), but apparently, I should strive for more bluntness, as it greatly increases the chances for reactions...
> 
> 
> 


More information about the swift-evolution mailing list