<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 24, 2015, at 3:05 PM, Joe Groff &lt;<a href="mailto:jgroff@apple.com" class="">jgroff@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><br class="Apple-interchange-newline">On Dec 24, 2015, at 12:17 PM, Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Dec 24, 2015, at 11:11 AM, Joe Groff &lt;<a href="mailto:jgroff@apple.com" class="">jgroff@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Dec 24, 2015, at 5:41 AM, Matthew Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">Sent from my iPad</span><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Dec 24, 2015, at 5:46 AM, Thorsten Seitz &lt;<a href="mailto:tseitz42@icloud.com" class="">tseitz42@icloud.com</a>&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">Am 22.12.2015 um 18:30 schrieb Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt;:<br class=""><br class="">My proposal is specifically suggesting that we treat “initial value” as a default rather than an initialization that always happens. &nbsp;IMO the current behavior is limiting and problematic in a number of ways.<br class=""><br class="">If we make the change I am suggesting double initialization / assignment will not happen.<span class="Apple-converted-space">&nbsp;</span><br class=""></blockquote><br class="">Ah, ok!<span class="Apple-converted-space">&nbsp;</span><br class=""><br class="">I'm a bit uneasy about overloading the initial-value-syntax with a new meaning, though.<br class=""><br class="">-Thorsten<br class=""></blockquote><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">This was pulled from the latest draft of the proposal. &nbsp;Please take a look at the current draft and let me know if you like the new solution better.</span><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"></div></blockquote></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">I wonder whether we could avoid the problems of mixing up inline initialization and default initializer parameterization by taking a different approach. Sorry if this has been discussed and I missed it, but Scala and Kotlin both support a compact function-like class declaration syntax for simple "case classes". We could adopt something similar for our structs and classes, so that:</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><blockquote class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px 0px 0px 40px; border: none; padding: 0px;">public struct Vec4(x: Double, y: Double, z: Double, w: Double = 1.0) { }</blockquote><blockquote class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px 0px 0px 40px; border: none; padding: 0px;"><br class=""></blockquote><span class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">expanded to:</span><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><blockquote class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class="">public struct Vec4 {</div><div class="">&nbsp; public let x: Double</div><div class="">&nbsp; public let y: Double</div><div class="">&nbsp; public let z: Double</div><div class="">&nbsp; public let w: Double // NB: No inline initializer</div><div class=""><br class=""></div><div class="">&nbsp; // Default argument in struct decl becomes default argument in initializer</div><div class="">&nbsp; public init(x: Double, y: Double, z: Double, w: Double = 1.0) {</div><div class="">&nbsp; &nbsp; self.x = x</div><div class="">&nbsp; &nbsp; self.y = y</div><div class="">&nbsp; &nbsp; /* you get the idea */</div><div class="">&nbsp; }</div><div class="">}</div><div class=""><br class=""></div></blockquote><span class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">(and you could presumably stick `var` on parameters to make the corresponding properties `var`s instead of `let`s, if you wanted). That collects all the information you want to know about the members and their initialization together in one place, and the syntax naturally suggests function-like semantics for `=` expressions rather than inline-initializer-like semantics.</span></div></blockquote><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Hi Joe, thanks for jumping in to this thread with an idea. &nbsp;</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">One thing that isn't obvious to me is how your idea would work when some properties need a default and some need an initial value? &nbsp;What about access control for properties in the struct parameter list? &nbsp;What about behaviors (assuming your proposal is accepted). &nbsp;</div></div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">One possibility is that you could provide additional properties that aren't involved in the memberwise initialization, which could then be given initial values:</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><div class=""><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;">public struct Vec4(x: Double, y: Double, z: Double, w: Double = 1.0) {</blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;">&nbsp; let xAxis = Vec4(x: 1, y: 0, z: 0)</blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;">}</blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><br class=""></blockquote>My totally-unsubstantiated hunch is that, for most types where you want a simple memberwise initializer, you don't usually need all that much customization on the properties. Once behaviors and other interesting modifiers come into play, it's more and more likely a synthesized initializer isn't going to cut it.</div></div></div></div></blockquote><div><br class=""></div><div>This is kind of what I guessed. &nbsp;I’d really prefer to keep memberwise initialization orthogonal to other features. &nbsp;I think it is a more straightforward approach and is also more flexible.</div><br class=""><blockquote type="cite" class=""><div class=""><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">I’ll have to give this some thought, but my initial reaction is that I would prefer a different path that sticks to current syntax and has clear interaction with other language features.</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Did you have a chance to see how I handled this in the latest draft by introducing the `@default` attribute?</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><pre class="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal; color: rgb(51, 51, 51);"><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">struct</span> S {
    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@default</span>(<span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span>hello<span class="pl-pds" style="box-sizing: border-box;">"</span></span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> s: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>
    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@default</span>(<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">42</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> i: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span>

    <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// user declares:</span>
    memberwise <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">init</span>(<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">...</span>) {}
    <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// compiler synthesizes:</span>
    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">init</span>(s: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> <span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span>hello<span class="pl-pds" style="box-sizing: border-box;">"</span></span>, i: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">42</span>) {
        <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/* synthesized */</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">self</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>s <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> s
        <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/* synthesized */</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">self</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>i <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> i
    }
}</pre><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Something like this attribute might also be useful in other cases allowing the default to be used by manual initializers:</div><div class=""><div class=""><br class=""></div><div class="">struct S {</div><div class="">&nbsp; let &nbsp;value: Int?</div><div class="">}</div><div class=""><br class=""></div><div class="">public class X {<br class="">&nbsp; @default(42) let a &nbsp; &nbsp; // same potential utility if this is a var</div><div class=""><br class=""></div><div class=""><div class="">&nbsp; &nbsp;// default is a keyword that is only valid in an expression</div><div class="">&nbsp; &nbsp;// on the rhs of a member initialization statement</div><div class="">&nbsp; &nbsp;// or possibly an initializer parameter with a name corresponding to a stored property</div></div><div class=""><br class=""></div><div class="">&nbsp; &nbsp;init(s: S) {</div><div class="">&nbsp; &nbsp; &nbsp; self.s = s.value ?? default &nbsp; &nbsp;</div><div class="">&nbsp; &nbsp;}</div><div class="">&nbsp; &nbsp;init(int a = default) { … }<br class="">}</div><div class=""><br class=""></div><div class="">As an alternative to specifying a value directly in the attribute, it could require a `let` member name, although my initial reaction is that this is more verbose and less good:</div><div class=""><br class=""></div><div class="">public class X {</div><div class="">&nbsp; &nbsp;let defaultForA = 42<br class="">&nbsp; @default(defaultForA) let a<br class="">}</div></div></div></div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">The '@default' idea was part of what prompted my response. It adds a bit of unfortunate complexity to the proposal, and I'm not sure how you would contextually resolve 'default' to the property whose default you want. I was hoping that maybe by exploring other approaches we could find a lower-energy state with all the important functionality.&nbsp;</div></div></blockquote><div><br class=""></div><div>I probably shouldn’t have even mentioned other possible uses of @default. &nbsp;If I understand what you find to be unfortunate complexity correctly it isn’t necessary for memberwise initialization proposal. &nbsp;</div><div><br class=""></div><div>For the memberwise initialization proposal the default is only used when synthesizing a memberwise initialization parameter. &nbsp;There is no need to contextually resolve the `default` keyword, in fact there is no `default` keyword at all in the memberwise initialization proposal. &nbsp;That was an unrelated idea for a possible use of @default in the future that I don’t think I communicated clearly. &nbsp;I don’t want to confuse the memberwise initialization proposal further so let’s just pretend I never mentioned it! :) &nbsp;Do you still have a concern if we only use @default for memberwise initialization as in this example:</div><div><br class=""></div><div>struct S {<br class="">&nbsp; &nbsp; @default("hello") let s: String<br class="">&nbsp; &nbsp; @default(42) let i: Int<br class=""><br class="">&nbsp; &nbsp; // user declares:<br class="">&nbsp; &nbsp; memberwise init(...) {}<br class="">&nbsp; &nbsp; // compiler synthesizes:<br class="">&nbsp; &nbsp; init(s: String = "hello", i: Int = 42) {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; /* synthesized */ self.s = s<br class="">&nbsp; &nbsp; &nbsp; &nbsp; /* synthesized */ self.i = i<br class="">&nbsp; &nbsp; }<br class="">}</div><div><br class=""></div><div>A variation on this syntax I think I actually like better would be:</div><div><br class=""></div><div>@default let s: String = “hello”</div><div><br class=""></div><div>Using this syntax the @default attribute changes the value from an initial value to a default value. &nbsp;The compiler would not perform initial value initialization synthesis for properties with the @default attribute, but it would use the default value when performing memberwise initialization parameter synthesis.</div><div><br class=""></div><div>The advantages to this are:</div><div><br class=""></div><div>1. The syntax does not allow for both a default value and an initial value (which wouldn’t make sense).</div><div>2. It feels cleaner, more familiar, and less cluttered.</div><div><br class=""></div><div>The obvious disadvantage is that some people might confuse it with initial values. &nbsp;Maybe using an attribute in this way isn’t a good idea.</div><div><br class=""></div><div>How do you feel about using @default if the value is only used when synthesizing memberwise initialization parameters? &nbsp;In that case the compiler is already synthesizing the parameter. &nbsp;There is no complexity in determining what property or default value is involved.</div><div><br class=""></div><div>If you do feel more comfortable with this memberwise only `@default` what do you think about the `@default let i: Int = 42` syntax?</div><div><br class=""></div><div>Matthew</div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">-Joe</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class="">That said, I think the interaction of explicit initializers and memberwise initializers begs discussion. &nbsp;It would be a much simpler model to only get memberwise parameters for properties without an explicit init. &nbsp;Have you considered this model, what are the tradeoffs with allowing vars to overwrite them? &nbsp;Allowing an explicit init to be overwritten by the memberwise initializer seems potentially really confusing, and since you allow explicit arguments on inits, this could always be handled manually if someone really really wanted it. &nbsp;For example, they could write:</div><div class=""><br class=""></div><div class="">memberwise init(s : String) {</div><div class="">&nbsp; self.s = s</div><div class="">}</div><div class=""><br class=""></div><div class="">If they wanted to get the sugar of memberwise inits (presumably for other properties without an explicit init) but still allow one to be overwritten.</div></div></div></div></blockquote><div class=""><br class=""></div><div class="">Personally, I think there is a lot of value in allowing memberwise initialization for properties that do contain an initial value. &nbsp;Imagine a hypothetical Swift version of Cocoa Touch. &nbsp;UILabel might have initial values for text, font, textColor, etc but still want to allow clients to provide memberwise initialization arguments to override the default value. &nbsp;I think there are many cases like this both in UI code and elsewhere. &nbsp;</div></div></div></blockquote></div><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class=""><br class=""></div><div class="">I think I confused the issue. &nbsp;If we have to support properties that have a default value, then the model I’m advocating for is that this:</div><div class=""><br class=""></div><div class="">class C {</div><div class="">&nbsp; let x : Int</div><div class="">&nbsp; var y&nbsp;: Int = foo()</div><div class=""><br class=""></div><div class="">&nbsp; memberwise init(...) {}</div><div class="">}</div><div class=""><br class=""></div><div class="">compile into:</div><div class=""><br class=""></div><div class="">init(x : Int, y : Int = foo()) {</div><div class="">&nbsp; self.x = x</div><div class="">&nbsp; self.y = y</div><div class="">}</div><div class=""><br class=""></div><div class="">Pertinent points of this are that lets without a default value would still turn into arguments, and that any side effects of the var initializer would be squished. &nbsp;Another potential model is to compile it to:</div><div class=""><br class=""></div><div class=""><div class="">init(x : Int, y : Int) {</div><div class="">&nbsp; self.x = x</div><div class="">&nbsp; self.y = foo()</div><div class="">}</div><div class=""><br class=""></div><div class="">which is guaranteed to run the side effect, but requires y to be specified. &nbsp;I do not think it is a good model to compile it to:</div><div class=""><br class=""></div><div class=""><div class="">init(x : Int, y : Int? = nil) {</div><div class="">&nbsp; self.x = x</div><div class="">&nbsp; self.y = y ?? foo()</div><div class="">}</div></div><div class=""><br class=""></div><div class="">because that would allow passing in an Int? as the argument. &nbsp;The final model (which I know you don’t like) is for memberwise initializers to *only* apply to properties without a default value.</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class="">This doesn’t seem like the right behavior to me. &nbsp;The compiler shouldn’t be in the business of scanning the body of the init to decide what members are explicitly initialized. &nbsp;I’d suggest that the model simply be that the contents of the {} on a memberwise init get injected right after the memberwise initializations that are done. &nbsp;This mirrors how properties with default values work.</div></div></div></div></blockquote><div class=""><br class=""></div><div class="">The model does inject the synthesized memberwise initialization just prior to the body of the initializer. &nbsp;</div><div class=""><br class=""></div><div class="">As written the proposal does scan the body of the init in order to determine which properties receive memberwise initialization. &nbsp;The idea here is that it provides additional flexibility as it allows specific initializers to “opt-out” of memberwise initialization synthesis for some properties while receiving it for others.</div></div></div></blockquote></div><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class=""><br class=""></div></div></div></div><div class="">This is a very problematic model for me, because it can lead to serious surprises in behavior, and in the case of lets, shares the problems above with not allowing one to define the long-hand form explicitly.</div></div></div></div></div></div></div></blockquote></div></div></div></blockquote></div></blockquote></div><br class=""></body></html>