I believe Erica's point about RIGHT NAMES ONLY is the most clear. While a block-like syntax using $0 is nice, it fails to communicate whether it is a newvalue or an oldvalue.<br><br>Therefore instead of following a block-like pattern it should follow a delegate-function like pattern. This would remove the ambiguity that $0 or name changing would present.<br><br><br>set (newValue: TheType) {<br> let a = newValue<br>}<br><br>didSet (oldValue: TheType) {<br> let b = oldValue<br>}<br><br><br><br><div class="gmail_quote"><div dir="ltr">On Sat, Dec 3, 2016 at 10:06 PM Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><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="gmail_msg"><div class="gmail_msg">[Original pitch: <a href="https://gist.github.com/erica/f5c58c689a6f479606c6158077c1962b" class="gmail_msg" target="_blank">https://gist.github.com/erica/f5c58c689a6f479606c6158077c1962b</a>]</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">GENERAL FEEDBACK</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I received a gratifying amount of feedback about my pitch here, on Twitter, </div><div class="gmail_msg">through email, on several Slack channels, and on IRC. I wanted to summarize </div><div class="gmail_msg">the feedback, to start a new round of discussion.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">* A majority of respondents believe the current feature is incorrectly designed </div><div class="gmail_msg"> and that this is our best opportunity to change it.</div><div class="gmail_msg">* A majority of respondents disagree on *how* it should be changed.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg">Before I commit to the (non-trivial) effort of pushing on this, I'd like to know if any </div><div class="gmail_msg">of the core team can chime in on the "preferred" design. Thank you.</div></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">BUG REPORT</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The notion that the compiler should check for `set(oldValue)`, `willSet(oldValue)`, </div><div class="gmail_msg">and `didSet(newValue)` and emit warnings or errors had pretty much universal</div><div class="gmail_msg">support. I have submitted <a href="https://bugs.swift.org/browse/SR-3310" class="gmail_msg" target="_blank">https://bugs.swift.org/browse/SR-3310</a> to address</div><div class="gmail_msg">this, regardless of whether the syntax changes or not.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">MENTIONING NAMES</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">A majority of respondents prefer that argument names always be mentioned, </div><div class="gmail_msg">whether or not they *can* be omitted. Consensus is that it's unSwifty</div><div class="gmail_msg">to use pre-built `newValue` and `oldValue` arguments without mentioning</div><div class="gmail_msg">them first.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">* The current system violates the principle of clarity. </div><div class="gmail_msg">* It adds too much magic (<a href="https://en.wikipedia.org/wiki/Magic_(programming))" class="gmail_msg" target="_blank">https://en.wikipedia.org/wiki/Magic_(programming))</a> </div><div class="gmail_msg"> at the point of use. </div><div class="gmail_msg">* It is inconsistent with the binding of variable names in closures.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">My original design, which I chose to provide the least impact on the compiler and </div><div class="gmail_msg">existing code, was the least popular option.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">PREFERRED DESIGN</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The most popular design is that setters and property observers follow closures</div><div class="gmail_msg">syntax, namely that the old value and new value arguments be passed as $0, </div><div class="gmail_msg">and assignable using `name in`. Under this design, a setter looks like:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">```</div><div class="gmail_msg">set { newValue in ... } // or</div><div class="gmail_msg">set { somethingElse in ... } // or</div><div class="gmail_msg">set { use $0 here }</div><div class="gmail_msg">```</div><div class="gmail_msg">Swift loses the "magic" newValue and oldValue, but any developer who</div><div class="gmail_msg">normally prefers to mention the name before use has a simple, visible</div><div class="gmail_msg">and easy way to retain that clarity. </div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">* Mirrors closure syntax</div><div class="gmail_msg">* Easy to use</div><div class="gmail_msg">* Loses magic names</div><div class="gmail_msg">* Encourages documenting names in context</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">"NO CHANGE"</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The second most popular design is "leave things as they are" (but implement the bug</div><div class="gmail_msg">report.) Developers with good style habits will use mandatory `newValue` and `oldValue`</div><div class="gmail_msg">names in their setter and observer declarations. No proposal is needed, and the bug</div><div class="gmail_msg">report guards against potential errors.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I would appreciate knowing whether the core team feels that the support for "no change",</div><div class="gmail_msg">even from a smaller group of developers, disqualifies this issue from the high bar of Phase 1.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">(This group also included the most developers who self-reported that they did not</div><div class="gmail_msg"> use the override feature.)</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">REMOVING OVERRIDES</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">A third design entirely loses the ability to override variables or mention their names. </div><div class="gmail_msg">This was in fact my *original* original design that I did not submit after sufficient </div><div class="gmail_msg">devs told me they wanted to always spell out magic argument names. </div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">RIGHT NAMES ONLY</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Finally, the least popular design is my original pitch. (Only allow the "right" names,</div><div class="gmail_msg">and allow them to be omitted.) This design has the least impact on the language, </div><div class="gmail_msg">causes the least breaking for most use-cases, and allows most pro coders to continue</div><div class="gmail_msg">using the "mention all names" approach.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">UPDATING PROPOSAL</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I am happy to update the proposal for the "closure-like" design. I believe there *was*</div><div class="gmail_msg">reasonable consensus that the current system is out of step with Swift's design goals</div><div class="gmail_msg">to push forward. However, I want this to go through another round of feedback.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Thank you in advance for your comments. If this does move forward to a proposal, it</div><div class="gmail_msg">must be discussed and decided in the first phase of Swift 4 as the change *is* breaking.</div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">-- Erica</div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><br class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Dec 1, 2016, at 10:22 PM, Derrick Ho <<a href="mailto:wh1pch81n@gmail.com" class="gmail_msg" target="_blank">wh1pch81n@gmail.com</a>> wrote:</div><br class="m_-6865028387290304174Apple-interchange-newline gmail_msg"><div class="gmail_msg">I like this proposal!<br class="gmail_msg"><br class="gmail_msg">+1<br class="gmail_msg"><br class="gmail_msg"></div></blockquote></div><br class="gmail_msg"></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>