[swift-evolution] Pitch: Remove default initialization of optional bindings
Jon Shier
jon at jonshier.com
Mon Nov 6 16:41:20 CST 2017
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
More information about the swift-evolution
mailing list