<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 6, 2016, at 4:52 PM, Howard Lovatt <<a href="mailto:howard.lovatt@gmail.com" class="">howard.lovatt@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><font size="2" class=""><span style="background-color:rgba(255,255,255,0)" class="">Here is an expanded proposal for the syntax for a Scala style memberwise syntax and equivalent code, specification is via an example rather than formal syntax since this is easier to follow. Note it is like Scala’s syntax but it is ‘Swiftified” (in particular still retains `init` keyword).<br class=""><br class=""> class Ex public init(<br class=""> superParam: sPType = sPInitial,<br class=""> private label privateParam: pPType = pPInitial,<br class=""> calculatedParam: cPType = cPInitial<br class=""> ): SuperType(superParam) {<br class=""> calculatedParam: cPType {<br class=""> get {…}<br class=""> set {…}<br class=""> }<br class=""> }<br class=""><br class="">This gets translated to:<br class=""><br class=""> class Ex: SuperType(superParam) { {<br class=""> private privateParam: pPType = pPInitial,<br class=""> public init(superParam: sPType = sPInitial, label privateParam: pPType = pPInitial, calculatedParam: cPType = cPInitial) {<br class=""> // 1. Call super<br class=""> super.init(superParam)<br class=""> // 2. Initialize generated parameters and existing parameters<br class=""> self.privateParame = privateParam<br class=""> self.calculatedParam = calculatedParam<br class=""> }<br class=""> calculatedParam: cPType {<br class=""> get {…}<br class=""> set {…}<br class=""> }<br class=""> }<br class=""></span></font></div></blockquote><div><br class=""></div><div>This translation is not valid Swift for several reasons. There are also several aspects of this translation that are somewhat vague and a detailed design is necessary to evaluate how you envision it working.</div><br class=""><blockquote type="cite" class=""><div class=""><font size="2" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class="">Because the syntax is so short it is part of this proposal to remove both the current default and memberwise initialisers thus simplifying the language overall (remove two features, add one) and at the same time gain power, which is a rare situation and therefore I would suggest optimal.<br class=""><br class="">It is also more powerful than the proposed `memberwise init(..)` and/or existing automatic `inits` in the following ways:<br class=""><br class="">1. Allows `lets` to have a default value.<br class="">2. Allows other properties including computed properties to have a default value.<br class="">3. Allows any `super.init` to be called (not restricted to `super.init()`).<br class="">4. Allows control of which properties participate in the `init` (they are listed in the brackets and are not in a super call and are not an existing property).<br class="">5. Allows private properties to be initialised.<br class="">6. Allows properties including private properties to have a label instead of their actual name and hence not expose internals (also allows migration of implementation whilst retaining external interface).<br class="">7. Allows calls to the generated `init` that don’t specify all members, i.e. for `struct Ex init(i: Int = 0, s: String = “") {}` the following are allowed `Ex()`, `Ex(i: 1)`, `Ex(s: “A”)`, and `Ex(i: 2, s: “B”)`.<br class="">8. Allows visibility of automatically generated `init` to be controlled.<br class="">9. Supports property behaviours.<br class="">10. Does not require a new keyword.<br class=""></span></font></div></blockquote><div><br class=""></div>Several of these points are also true of my proposal and several others would be true if what I believe are the most important future enhancements are added. </div><div><br class=""><blockquote type="cite" class=""><div class=""><font size="2" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class="">The downsides of the proposal relative to `memberwise init(..)` and/or existing automatic `inits` are:<br class=""><br class="">1. That people would need to be careful when laying out their code otherwise the first line could become long (a bit of pretty printing solves this).<br class="">2. Existing structs/classes that have automatically generated inits would need to be refactored, e.g. `CGRect` would become `struct CGRect init(var origin: CGPoint, var size: CGSize) {}` (a migration tool would help here).<br class=""><br class="">Other than the downsides listed above the proposal does everything the current proposal and current implementation does and more (more also listed above) and is simpler to both explain and implement.<br class=""></span></font></div></blockquote><div><br class=""></div><div>This is not true. There are additional differences. </div><br class=""><blockquote type="cite" class=""><div class=""><font size="2" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class="">The above more than addresses the reasons given in the current proposal for not using the Scala syntax and demonstrates superiority in many areas. </span></font></div></blockquote><div><br class=""></div><div>I disagree. The current proposal clearly states reasons not addressed here.</div><div><br class=""></div><div>I don’t wish to </div><br class=""><blockquote type="cite" class=""><div class=""><font size="2" class=""><span style="background-color:rgba(255,255,255,0)" class="">However if it were the current proposal or nothing I would go with the current proposal since something is better than nothing.</span></font></div></blockquote><blockquote type="cite" class=""><div class=""><br class="">On Wednesday, 6 January 2016, Matthew Johnson <<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 5, 2016, at 12:12 PM, Tino Heth <<a href="javascript:_e(%7B%7D,'cvml','2th@gmx.de');" target="_blank" class="">2th@gmx.de</a>> wrote:</div><br class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">The “type parameter list” syntax is sugar that could be implemented as a layer on top of the current proposal or could be implemented orthogonally.<br class=""></blockquote>Hi Howard,<br class="">I've heard this argument before, so I'll repeat my answer as well:<br class="">Both offers don't make sense, it's either one way or the other (or something completely different).<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">I don’t think it’s clear whether both make sense or not. They are not mutually exclusive and are aimed at solving related, but different problems. If we adopt the current proposal, the Kotlin / Scala syntax *might* make sense for some use cases. It would depend upon whether the current proposal is considered too verbose in enough cases or not. This may or may not turn out to be the case.</div><div class=""><br class=""></div><div class="">The reason my proposal looks the way it does is because there are specific goals it intends to achieve and problems it is intended to solve. These goals and problems are not adequately addressed by the Kotlin / Scala syntax.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">If diversity starts here, why not have "const" and "val" beside "let", or allow "fn" and "lambda"?<br class=""><br class="">@Matthew: Please, if you support something, then say so - using clear words, not phrases like "could be implemented”.<br class=""></div></div></blockquote><br class=""></div><div class="">This phrasing is plenty clear IMO. I am stating a possibility. I do not have a position on whether or not it is a good idea at the moment.</div><div class=""><br class=""></div><div class="">I have made some modifications to the proposal over the last few days. These changes have been partly motivated by considering the conversation we have had. You may wish to give it another look. If so, please look here: <a href="https://github.com/anandabits/swift-evolution/blob/flexible-memberwise-initialization/proposals/0018-flexible-memberwise-initialization.md" target="_blank" class="">https://github.com/anandabits/swift-evolution/blob/flexible-memberwise-initialization/proposals/0018-flexible-memberwise-initialization.md</a>. There is currently an open PR for the latest change so it is not in the main Swift evolution repo yet.</div><div class=""><br class=""></div><div class="">The most recent change includes a discussion of why it does not use the Scala / Kotlin syntax. You may not like the choice but I hope you can at least understand the rationale (even if you disagree with it).</div><div class=""><br class=""></div><br class=""></div></blockquote><br class=""><br class="">-- <br class=""> -- Howard.<br class=""><br class="">
</div></blockquote></div><br class=""></body></html>