[swift-evolution] Remove Failable Initializers
jordan_rose at apple.com
Wed Mar 9 15:15:33 CST 2016
> On Mar 9, 2016, at 12:35, David Owens II via swift-evolution <swift-evolution at swift.org> wrote:
>> On Mar 9, 2016, at 12:02 PM, Tino Heth <2th at gmx.de <mailto:2th at gmx.de>> wrote:
>> I have to admit that initialization in Objective-C not only had the downside of being more cumbersome, but also the advantage of being simpler and more lightweight.
> It is more cumbersome because it's significantly more powerful and tied to a class-hierarchy. That power also makes it "unsafe". Like most recent languages, Swift has gone the route of combining both allocation and initialization into one unifying concept. This is primary source of the init() constraints, limitations, and complexity. There's a lot to get right when your stance is that a type must be fully initialized before returning it to the caller.
This is not correct. Even if Swift had separated allocation and initialization, you would still have all of the "constraints, limitations, and complexity". It's the full initialization that forces this, not the combination with allocation.
Every rule Swift enforces was a "rule" in Objective-C; you were just free to ignore it there. Between safety and convenience, Swift chooses safety. That said, I'm/we're still hoping to come with simpler, improved initialization rules. (I should really post my summary of problems with the current model somewhere. It probably doesn't cover all the problems, but it's a good starting point for discussion.)
Additionally, from earlier:
> Unfortunately, Swift decided to make init() a special case thing. It's also the only function type that has special rules around accessing properties, the only one that cannot be named differently, the only one that has special rules around recursing or forwarding to other init() calls, and many other special rules and considerations.
I disagree with most of this. Property and subscript accessors, deinitializers, and closure expressions all have different rules from plain old 'func' (which itself behaves differently as a type member vs. top-level). Objective-C makes all of these things methods, which is very uniform but causes problems where they should differ in behavior.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution