<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 Jan 7, 2016, at 8:30 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 7, 2016, at 11:30 AM, Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 7, 2016, at 12:51 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 7, 2016, at 10:49 AM, Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.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 Jan 7, 2016, at 12:37 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=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 7, 2016, at 10:32 AM, David Owens II &lt;<a href="mailto:david@owensd.io" class="">david@owensd.io</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;">And this is more clear than this?</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;"><font face="Menlo" class=""><br class=""></font></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;"><font face="Menlo" class="">class Foo {<br class=""></font><font face="Menlo" class="">&nbsp; var x,y,z: Int<br class=""></font><font face="Menlo" class="">&nbsp; init(x: Int, y: Int, z: Int) {</font></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;"><font face="Menlo" class="">&nbsp; &nbsp; self.x = x</font></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;"><font face="Menlo" class="">&nbsp; &nbsp; self.y = y</font></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;"><font face="Menlo" class="">&nbsp; &nbsp; self.z = z</font></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;"><font face="Menlo" class="">&nbsp; }</font></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;"><font face="Menlo" class="">}</font></blockquote></div></blockquote></div><br class=""><div class="">No, it isn't, but Matthew asked… I'm personally not too motivated to support anything more than all-or-nothing memberwise initialization, and tend to agree that anything more specialized deserves an explicit implementation.</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="">Maybe you would feel differently if you were an app developer. &nbsp;Different kinds of code have different needs. &nbsp;The most important use cases I have in mind are related to UI code, which is often the majority of the code in an app.</div></div></blockquote><br class=""></div><div class="">Do you have any concrete examples in mind?</div><div class=""><br class=""></div><div class="">-Joe</div><br class=""></div></div></blockquote><br class=""></div><div class="">Here is an example where partial memberwise initialization would apply. &nbsp;It is similar to something in a real project:</div><div class=""><br class=""></div><div class="">public class FontPicker: UIControl {</div><div class="">&nbsp; public let fonts: [UIFont]</div><div class=""><br class=""></div><div class="">&nbsp; public var fontSize: CGFloat = 22</div><div class="">&nbsp; public var foregroundColor: UIColor = UIColor.darkGrayColor()</div><div class="">&nbsp; public var backgroundColor: UIColor = UIColor.whiteColor()</div><div class="">&nbsp; // A bunch of other appearance attributes here</div><div class=""><br class=""></div><div class="">&nbsp; private let collectionView: UICollectionView</div><div class="">&nbsp; private let layout: UICollectionViewLayout</div><div class="">&nbsp; // other internal state required by the implementation</div><div class=""><br class=""></div><div class="">&nbsp; public memberwise init(...) {</div><div class="">&nbsp; &nbsp; // configure the collection view and add it as a subview</div><div class="">&nbsp; }</div><div class="">}</div><div class=""><br class=""></div><div class="">A couple points are relevant here:</div><div class=""><br class=""></div><div class="">1. Memberwise initialization is very valuable for the appearance attributes, but is useless if it exposes our implementation details.</div><div class=""><br class=""></div><div class="">2. In many custom UI widgets the appearance attributes don’t really need to be mutable post-initialization. &nbsp;At the same time, it is necessary to allow, but not require a value to be specified. &nbsp;It would be ideal if they were `let` properties with a default value, but still able to participate in memberwise initialization. &nbsp;Without that capability we are forced to choose between the advantages of using a `let` property and the advantages of memberwise initialization.</div><br class=""><div class="">UI widgets are a great example. &nbsp;View controllers often have a similar divide between state provided by the user and state related to internal implementation details.</div></div></div></blockquote><br class=""></div><div class="">Access control seems like a poor tool for the kind of categorization you want here. The vast majority of code is app code, where there's no reason to use 'public', so 'internal' and 'private' are the interesting visibility layers. Using 'private' to opt fields out of memberwise initialization is too brittle, in my opinion—You've made it much harder to factor the class's functionality into different files in the future, since you can no longer change any of these fields to internal without also breaking all of the memberwise initializers as a second-order effect.</div></div></div></blockquote><div><br class=""></div><div>One thing I should have mentioned in the reply last night is that the problem of breaking the memberwise initializers when access control changes is solvable. &nbsp;Several of the possible enhancements are attempts to allow the programmer to be more explicit when the rules don’t do the right thing. &nbsp;The breakage you describe is an example where that would be necessary.</div><div><br class=""></div><div>The solution I believe is the best one (assuming the automatic model) is allowing distinct access control for initialization. &nbsp;Initialization is conceptually distinct from both getting and setting. &nbsp;We already allow programmers to specify distinct access levels for `get` and `set` (for `var`), but we don’t for `init`. &nbsp;It feels like a natural extension of the access control model to allow a distinction for initialization. &nbsp;The `init` access level could also be used in phase 1 for manually written initializers, rather than the `get` visibility of a `let` property and the `set` visibility of a `var` that is used today.</div><div><br class=""></div><div>It would solve the problem problem you mention above by allowing the access control to be specified as `internal private(init)` rather than just `internal`. &nbsp;This access control change would have no impact on memberwise initializers.</div><div><br class=""></div><div>This would also solve the problem you mentioned earlier that `let` properties more capable than `private(set) var` properties. &nbsp;It would no longer be necessary to use the `set` access level because there would be a distinct access level for `init`. &nbsp;In that case, the programmer could specify exactly what is desired:&nbsp;</div><div><br class=""></div><div>1. `public private(set)` would allow public memberwise initializers to synthesize a parameter for the property</div><div>2. `private public(get)` would only allow private memberwise initializers to&nbsp;synthesize a parameter for&nbsp;the property. &nbsp;Only the getter would be visible publicly.</div><div>3. `public private(init)` would only allow private memberwise initializers to&nbsp;synthesize a parameter for&nbsp;the property. Both the getter and setter would be visible publicly.</div><div><br class=""></div><div>Ultimately, I think the automatic model is only a good idea if we enforce access control. &nbsp;Allowing the distinction to be made solves the problems you have pointed out while also allowing the programmer to get the desired behavior out of the automatic model in most or all cases. &nbsp;For those reasons I think it would be a significant improvement over the current proposal.</div><div><br class=""></div><div>Matthew</div></div></body></html>