[swift-evolution] Remove Failable Initializers

Thorsten Seitz tseitz42 at icloud.com
Wed Mar 9 00:23:07 CST 2016

Brent already wrote a lengthy mail explaining why the overhead of having to define errors is not "some keystrokes".
Let me add to that the following: 
If I have a simple case where I just want to skip failed initializations the errors won't help me anything in unexpected cases because I disregarded them anyway. And when I'm debugging unexpected cases then I will look at the arguments and the control flow and will have the same information an error would have given me. And simple errors or "middle ground" errors won't help me either.
On top of that I don't think that creating all those errors, possibly with non trivial algorithms like Brent explained, can be easily optimized away.

I don't think that redundancy is a problem here as it is only a partial overlap of functionality with different properties which both have their use. 


> Am 08.03.2016 um 22:09 schrieb Haravikk <swift-evolution at haravikk.me>:
>>> On 8 Mar 2016, at 15:26, Thorsten Seitz <tseitz42 at icloud.com> wrote:
>>> Am 08.03.2016 um 11:07 schrieb Haravikk via swift-evolution <swift-evolution at swift.org>:
>>> Just because someone opts to use error handling over a failable initialiser doesn’t mean they have to go overboard on the detail of their errors; it’s entirely possible to pick a reasonable middle-ground.
>> And it is entitely possible to just use an optional. If you prefer to use error handling over failable initializers, fine, just do so, but don't force it on others who are perfectly happy with the option to use optionals, too.
> It’s not an issue of ideology but of redundancy; the failable initialiser does nothing that error handling can’t do just as easily, the only difference is that instead of returning nil, you throw an appropriate error.
> The few extra characters are hardly going to kill you, while a thrown error (with common ones available for simplicity) can describe what went wrong in more detail than just “something went wrong”. Point is that we have two ways of achieving the same goal, but error handling encourages developers to think more about what type(s) of error to throw at each point; even just simple error types with no further detail can provide more information simply by being different, for example if you have a NonNumericError vs EmptyStringError types, the errors themselves tell you all you’re likely to need to know (hopefully there’d be a good set of common types).
> There are also some cases where failable initialisers can have subtle errors, for example, can you tell me where I might run into problems with the following:
> struct MyType {
>     let elements:[String]
>     func asInt(index:Array<String>.Index) -> Int? {
>         if self.elements.indices.contains(index) {
>             return Int(self.elements[index])
>         }
>         return nil
>     }
> }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160309/a50412b3/attachment.html>

More information about the swift-evolution mailing list