[swift-evolution] [Proposal Draft] Flexible memberwise initialization

Matthew Johnson matthew at anandabits.com
Tue Dec 22 13:02:02 CST 2015

> On Dec 22, 2015, at 12:51 PM, Guillaume Lessard via swift-evolution <swift-evolution at swift.org> wrote:
> Hi,
> Regardless of anything else in the proposal, I strongly dislike its attempted subversion of `let` properties.
> struct A {
>  let member = 1 // It’s done, over. If that’s not what you want, don’t initialize it here.
> }

This is not an attempt to subvert `let` properties.  The `= 1` in the declaration can very reasonably be viewed as a default value that should be used if the member is not otherwise initialized.

Why would you have an immutable instance member that is always going to have a constant value of 1?  That just wastes space by duplicating the constant value in many instances.  However it is quite reasonable to have an immutable instance member that defaults to 1, but may have a different value depending on the initializer that is used for the instance.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151222/8f675e5b/attachment.html>

More information about the swift-evolution mailing list