[swift-evolution] Remove Failable Initializers
2th at gmx.de
Wed Mar 9 11:20:19 CST 2016
> let i: Int = Int.init(123)
> would not compile if that initializer had a return type of Void rather than Int.
No one can argue the observation that init-methods have return values (although I think it's rather uncommon to invoke them that way) — but that is not my point:
Let's imagine I write a library with a numeric type, and define the "+"-operator to perform a multiplication.
let x: StringIntLiteralConvertible = 2 + 5
should assign x a value of 10: That is how the operation is defined (like "init" is defined to return self), and according to your argumentation, everything is fine.
Nonetheless, I'd say this operator is inconsistent, because it contradicts to common behavior, and "+" should be linked to addition.
Initializers behave similar (on another level, though):
They have the signature of a void function, they have the body of a void function — but yet they return something.
You are right that this is actually a topic on its own, as "init?" just emphasizes the "oddity", because suddenly there is a need to manually add a return statement for one case...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution