<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 8, 2016, at 11:03 AM, Paul Cantrell via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><b class="">What is your evaluation of the proposal?</b><br class=""><br class="">I have reservations about it. I think it should be deferred in search of a more generic solution, perhaps to be resurrected if the search for generality fails.<div class=""><br class=""></div><div class="">I appreciate the tremendous care that has obviously gone into the proposal. The dual attention to use cases and corner cases is admirable. The proposal present a thorough understanding of the problem that includes considerations I certainly hadn’t thought of!</div></div></div></blockquote><div><br class=""></div>Thanks Paul!</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">Still, I can’t shake unease about the proposed solution. As I read the examples, they’re not quite self-explanatory: a lot of magic, but the result doesn’t feel quite magical. Without being able to see what the compiler synthesizes, it’s often not obvious what will happen. As I read the detailed rules, they all sound quite sensible, but taken together feel like they’ll be hard to keep track of, and will lead to a lot of frustrated experimenting with the compiler. Tricky questions lurk all over. For example, what happens when I have a 7-member struct, all 7 parameters use memberwise initialization, but then I want to add some custom logic for the initialization of member 3? I think I have to either reorder the params or abandon … altogether? I feel like those tricky questions should melt away once I grasp the underlying principle, but there isn’t one to grasp; it’s just a bunch of tricky cases.</div><div class=""><br class=""></div><div class="">On reflection, it comes down to this:<b class=""> the feature to functionality ratio is too high.</b></div></div></div></blockquote><div><br class=""></div><div>Would you propose removing the current implicit memberwise initializer for structs on the same grounds? This proposal effectively fleshes that feature out giving it more functionality. The only fundamental complexity it adds is the access control rules, which I feel are pretty important to enforce.</div><div><br class=""></div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">That probably requires some explanation. By “feature,” I mean a specific behavior the software implements for which users will need a mental model. By “functionality,” I mean the set of things one can do with the software, and more importantly the nature of the user’s experience doing them.</div><div class=""><br class=""></div><div class="">An example of a high feature/functionality payoff is Swift’s as-if-immutable structs. There’s a fairly large set of relevant features: the let/var distinction for declarations, the “mutating” keyword, the interaction of “let” with setters and mutating methods, and the way “let” recursively affects structs inside of structs. However, all of that folds into a mental model with a nice unifying principle: Swift structs behave <i class="">semantically</i> as if they are all always immutable and mutations create a new struct and reassign it to the variable; however, they <i class="">perform</i> better than that, because the compiler will optimize that into a direct mutation when possible. The features pay huge functionality dividends across a wide variety of situations: defensive programming, passing data across threads, isolating responsibility … it goes on.</div><div class=""><br class=""></div><div class="">(Really, “functionality” is a qualitative thing, more about the experience than just “what can I do,” and so talking about the “feature to functionality ratio” is only a metaphorical gesture. It captures the right feeling, though.)</div><div class=""><br class=""></div><div class="">In this proposal, there’s a similarly large set of new features: the “memberwise” keyword, the new use of …, multiple interacting rules about memberwise property eligibility, synthesized initialization, rules about how that interacts with manual initialization. For all that, though, the functionality gain is limited: we shed some senseless repetition — that’s good! — but only for copying of parameters to properties, only when they’re in the same order, and only in initializers.</div><div class=""><br class=""></div><div class="">The proposal reads like a set of specific use cases translated directly into specific features, without a good eye to the bigger picture.</div><div class=""><br class=""></div><div class="">It feels to me like this functionality should come from a feature set that is more general, more arbitrarily composable, and pays greater dividends in a wider variety of situations. As a simple example, what if I want to write an updateFrom(other: Self) method that does a mass copy of all properties? Why doesn’t this proposal help with that, too? Because the … placeholder and the synthesized copying are tightly coupled (1) to each other and (2) to initialization.</div><div class=""><br class=""></div><div class="">I’m not sure what the better answer is, but it’s out there. I didn’t follow the whole discussion, but I did notice Joe Groff’s proposal for a Members tuple; that seems to me to be getting much warmer. I’d much prefer something along those lines, even if it were slightly more verbose.</div></div></div></blockquote><div><br class=""></div><div>I think the direction suggested by Joe (and Dave) is interesting. But they haven’t explained how it would handle some important use cases this proposal addresses (default parameter values, subset of members without using a struct, etc). If we are going to reject this proposal in hope of a more general solution I would at least like to see a path forward that might be able to address these use cases.</div><div><br class=""></div><div>More importantly, the general features on their own would not address the problems addressed by this proposal. There would still need to be initializer-specific magic. Joe hinted at what that might be but has not fleshed out all the details yet. Maybe it would be a simpler model but we would need to see more specific details.</div><div><br class=""></div><div>I don’t believe a fully generalized solution is possible. There are a lot of initialization-specific constraints that must be met (definitive initialization, single initialization of `let` properties, etc).</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><br class=""></div><div class="">(Aside, a small nitpick, but it really bugs me: initialization has O(M+N) complexity, not O(M×N) complexity. One doesn’t initialize every member with every parameter.)</div></div></div></div></blockquote><div><br class=""></div><div>MxN is members x initializers.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><br class=""><br class=""><b class="">Is the problem being addressed significant enough to warrant a change to Swift?</b><br class=""><br class="">It’s certainly worth considering. Mindless parameter copying is a source of low-value verbosity, and can lead to errors.<br class=""><br class=""><br class=""><b class="">Does this proposal fit well with the feel and direction of Swift?</b><br class=""><br class="">It does in that it aims to reduce developer error and verbosity by providing an idiom to solve a common problem.</div><div class=""><br class=""></div><div class="">It does not in that the idiom is so narrow. The language is moving away from that in other realms (e.g. lazy).</div><div class=""><br class=""><br class=""><b class="">If you have you used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?</b><br class=""><br class="">I’ve never heard of a language with such a high specialized tool for doing just this.</div><div class=""><br class=""></div><div class="">Ruby and Javascript allow programmatic traversal of both arguments and properties, and provide enough reflection to automate that. Developers in both languages do write ad hoc solutions to do almost exactly what this proposal does, though they’re not widely used. The most common is probably variations on this:<br class=""><b class=""><br class=""></b></div><div class="">def initialize(**args)</div><div class=""> args.each do |prop, value|</div><div class=""> obj.send("#{prop}=", value)</div><div class=""> end</div><div class="">end</div><div class=""><br class=""></div><div class="">…which uses key/value pairs from an argument array to set properties.</div><div class=""><br class=""></div><div class="">Being able to convert arguments to a dictionary is something Swift certainly might investigate.</div></div></div></div></blockquote><div><br class=""></div><div>We should have a safe solution that allows the compiler to enforce type checking and definitive initialization rules.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><b class=""><br class=""></b></div><div class=""><b class=""><br class=""></b></div><div class=""><b class="">How much effort did you put into your review? A glance, a quick reading, or an in-depth study?</b></div><div class=""><br class=""></div><div class="">I read the proposal carefully, but only lightly skimmed the discussion and other reviews.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">Paul<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Jan 6, 2016, at 4:47 PM, Chris Lattner via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">Hello Swift community,<br class=""><br class="">The review of "Flexible Memberwise Initialization" begins now and runs through January 10th. The proposal is available here:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0018-flexible-memberwise-initialization.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0018-flexible-memberwise-initialization.md</a><br class=""><br class="">Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""><br class="">or, if you would like to keep your feedback private, directly to the review manager.<br class=""><br class="">What goes into a review?<br class=""><br class="">The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>* What is your evaluation of the proposal?<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>* Is the problem being addressed significant enough to warrant a change to Swift?<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>* Does this proposal fit well with the feel and direction of Swift?<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>* If you have you used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>* How much effort did you put into your review? A glance, a quick reading, or an in-depth study?<br class=""><br class="">More information about the Swift evolution process is available at<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>https://github.com/apple/swift-evolution/blob/master/process.md<br class=""><br class="">Thank you,<br class=""><br class="">-Chris<br class="">Review Manager<br class="">_______________________________________________<br class="">swift-evolution mailing list<br class="">swift-evolution@swift.org<br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote><br class=""></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=eLFMrKDT8iBxZ-2Fbnk-2BZqvSchNN-2FvYXdceA0T7VxwkAdj-2BzuQTxiwCiRxJTBreq-2B1a7WHT3HtBGZwOqRKyhzZwcLOweOO-2FD7407g1OD3SjY5ZMcP-2Fv0qMf9Glk-2Bh7og4uFKzo8W0b9-2Bt4IH4ywyY4QdYsY08cMbgXH717VYKFH1KceIw7kgmaEFnOzDEVW-2BhnIpEwtuNn-2Be8ML-2BV3SoYA-2B0kHwgEeOmP56127v5ilkwg-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>