[swift-evolution] Pitch: Remove default initialization of optional bindings

Slava Pestov spestov at apple.com
Mon Nov 6 17:26:51 CST 2017


It sounds like several people rely on this behavior and are actually aware that it exists, so I won’t pursue the issue further.

Thanks for the feedback!

> On Nov 6, 2017, at 3:07 PM, Alejandro Martinez <alexito4 at gmail.com> wrote:
> 
> I won’t complain a lot if it’s decided to be removed but I would prefer it to stay. I use it constantly.
> 
> Sent from my iPad
> 
>> On 6 Nov 2017, at 22:41, Jon Shier via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>>   I use this on all of my mutable optional properties, when I have to use them. It’s just that little extra bit of code I don’t need to write, and it feels a lot like parameter defaults in use. By surface area, I assume you mean the fact that it’s an implicit behavior people may need to remember? As something like that, this seems like a very small one. As for users knowing about it, I’m guessing it falls into one of those things that people just never explicitly notice but would likely have a huge impact on anyone with lots of mutable optionals. Developers from other languages may also assume this behavior, since it replicates the “nil by default” behavior seen in other languages. 
>>   Ultimately, while I won’t feel this deeply, since I tend to view mutable optionals as poor practice in Swift, it’s a nice little convenience that will likely impact everyone using mutable optionals. If you really want to find out, perhaps run it agains the compatibility suite?
>> 
>> 
>> Jon
>> 
>>> On Nov 6, 2017, at 5:33 PM, Slava Pestov via swift-evolution <swift-evolution at swift.org> wrote:
>>> 
>>> Hi all,
>>> 
>>> Right now, the following two declarations are equivalent:
>>> 
>>> struct S {
>>> var x: Int?
>>> }
>>> 
>>> struct S {
>>> var x: Int? = nil
>>> }
>>> 
>>> That is, mutable bindings of sugared optional type (but not Optional<T>!) always have a default value of ‘nil’. This feature increases the surface area of the language for no good reason, and I would like to deprecate it in -swift-version 5 with a short proposal. Does anyone feel strongly about giving it up? I suspect most Swift users don’t even know it exists.
>>> 
>>> Slava
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list