<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="">This is some sort of a cross-post from another thread ["automatic protocol forwarding"] — for anyone who wants to follow, I recommend to read&nbsp;<a href="https://kotlinlang.org/docs/reference/classes.html" class="">https://kotlinlang.org/docs/reference/classes.html</a><div class="">The idea of "function-like class declaration" has been introduced here by Joe Groff, but apparently, its benefits have been underestimated.</div><div class=""><br class=""><blockquote type="cite" class="">If you feel Kotlin’s approach is better please respond to the memberwise initialization thread with some examples written in both Kotlin and in Swift using the memberwise initialization feature I am proposing to demonstrate how and why you think it is better.</blockquote><br class=""><div class=""></div><blockquote type="cite" class=""><div class="">Here is Kotlin:</div><div class="">class Person constructor(firstName: String, lastName: String) {</div><div class="">}</div></blockquote><div class="">That is a bad start — do you want to make Kotlin look worse than it is? You can just write "class Person(firstName: String, lastName: String)", the other syntax merely exists to allow designated constructors with special access restrictions.</div><br class=""><blockquote type="cite" class=""><div class="">Here is Swift under my proposal:</div><div class="">class Person {</div><div class="">&nbsp; &nbsp; var firstName: String</div><div class="">&nbsp; &nbsp; var lastName: String</div><div class="">&nbsp; &nbsp; // compiler synthesizes memberwise init</div><div class="">}</div><div class=""><br class=""></div><div class="">However, my proposal gives you a lot of additional flexibility:</div></blockquote><div class="">I deny that, and even if it is true, there is a price to pay — and that is more than the lines of code that are required...</div><br class=""><blockquote type="cite" class=""><div class="">1. It interacts well with access control</div></blockquote><div class="">Better than Kotlin? Please prove this.</div><br class=""><blockquote type="cite" class=""><div class="">2. Partial memberwise initialization is possible</div></blockquote><div class="">The same with Kotlin — and imho at least as easy</div><br class=""><blockquote type="cite" class=""><div class="">3. It allows memberwise initializers to accept non-memberwise parameters to initialize private state</div></blockquote><div class="">I think this can be achieved with less effort using function-like class declaration (afair Joe already gave an example)</div><br class=""><blockquote type="cite" class=""><div class="">4. More than one memberwise initializer is possible</div></blockquote><div class="">Kotlin has no need for memberwise initializers at all, and I see this as a big advantage</div><br class=""><blockquote type="cite" class=""><div class="">5. Memberwise initialization of properties with declaration modifiers, behaviors / delegates is possible</div></blockquote><div class=""><a href="https://kotlinlang.org/docs/reference/delegated-properties.html" class="">https://kotlinlang.org/docs/reference/delegated-properties.html</a></div><div class="">(afaik this is not only possible, it's handled by the current compiler for a long time)</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class="">And probably more. &nbsp;My approach was to design a solution that fits into the current Swift language and is orthogonal to other language features as much as possible.</div></blockquote><div class=""><div class="">Afaics there not much room left for the promised additional flexibility… and the problem with default values for constants just doesn't exist in Kotlin at all.</div></div><div class=""><br class=""></div><div class="">I neither state your proposal is bad, nor that we should simply copy an existing solution, but even as a big fan of Swift, I have to admit that Kotlin (which I probably will never use in real projects) clearly performs better in this area:</div><div class="">It's more concise, it doesn't need "required" nor "convenience", it offers an intuitive syntax for forwarding and it is easy to grasp.</div><div class=""><br class=""></div><div class="">I know that I'm not just challenging your own, personal ideas here, and have no illusions about the outcome of this bold move — but it is my honest opinion this proposal might (in total) be better than the status quo, but is inferior to Kotlin in every aspect (whereas the current scheme has the edge of familiarity on its side).</div><div class=""><br class=""></div><div class="">Best regards,</div><div class="">Tino</div></div></body></html>