[swift-evolution] Remove Failable Initializers
Jens Persson
jens at bitcycle.com
Wed Mar 9 05:42:42 CST 2016
Ehrm, correction:
If initializers were void-functions in every aspect, how would we explain
what happens here:
let a: Int = Int.init(123)
let b: Int? = Int.init("ff", radix: 16)
print(a) // 123
print(b) // Optional(255)
?
On Wed, Mar 9, 2016 at 12:41 PM, Jens Persson <jens at bitcycle.com> wrote:
>
> > Swift, on the other hand, is different:
> > Init-methods are void-functions in every aspect, with the irregularity
> > that we can return "nil" (if the initializer is marked accordingly).
>
> Initializers are clearly not void-functions, as they return a value of
> type T.
> And failable initializers return an Optional<T>.
> Where T is the type to which the initializer belongs.
>
> If initializers where void-functions in every aspect, how would we explain
> what happens here:
> let a: Int = Int.init(123)
> let b: Int? = Int.init("ff", radix: 16)
> print(a) // 123
> print(b) // 255
> ?
>
> /Jens
>
>
> On Wed, Mar 9, 2016 at 11:32 AM, Tino Heth via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> As ease of use and performance implications have been discussed, I would
>> still like to see the question of consistency addressed:
>> In Objective-C, returning nil from an initializer is nothing special — it
>> is a regular function that returns id (self in most cases).
>>
>> Swift, on the other hand, is different:
>> Init-methods are void-functions in every aspect, with the irregularity
>> that we can return "nil" (if the initializer is marked accordingly).
>>
>> Am I the only one who has the feeling that this is a little bit odd?
>> What kind of method is a initializer in Swift?
>>
>> Tino
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>
>
>
> --
> bitCycle AB | Smedjegatan 12 | 742 32 Östhammar | Sweden
> http://www.bitcycle.com/
> Phone: +46-73-753 24 62
> E-mail: jens at bitcycle.com
>
>
--
bitCycle AB | Smedjegatan 12 | 742 32 Östhammar | Sweden
http://www.bitcycle.com/
Phone: +46-73-753 24 62
E-mail: jens at bitcycle.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160309/8ac96209/attachment.html>
More information about the swift-evolution
mailing list