[swift-evolution] Remove Failable Initializers

Jordan Rose jordan_rose at apple.com
Tue Mar 8 17:01:38 CST 2016


> On Mar 3, 2016, at 13:43, Haravikk via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> The duality is that an error reported through the throwing mechanism should be non-trivial.
> 
> Is calling an initialiser with invalid values really trivial?

Without responding to anything else, there are several cases where the work to validate that a parameter is valid is pretty much equivalent to the work to create the instance. It's a pragmatic decision, then, to accept "invalid" values and return nil rather than trapping out with a precondition(_:).

That doesn't mean an error couldn't be thrown either, but such invalid parameters are usually intended to be handled right at the call site, while thrown errors are very often meant to be propagated up to the start of the activity.

Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160308/d8e137c6/attachment.html>


More information about the swift-evolution mailing list