<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="">Comments below<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">Am 06.05.2016 um 13:48 schrieb Haravikk via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>:</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=""><div class="">Actually a setter has more in common with a function, in which case the let implicit, the difference is that a setters type is also implicit. In fact, you don’t even need to specify a name in a setter at all, as the default is newValue and you can just use that.</div><div class=""><br class=""></div><div class="">I’m more curious whether we even need a named new value at all, or if setters should just look like the following instead:</div><div class=""><br class=""></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>set { sideLength = $0 / 4.0 }</font></div></div></div></blockquote><div><br class=""></div><div>This is great!</div><div>Why not have the opportunity to name the variable like in closures, but have it default to $0:</div><div><br class=""></div><div><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><font face="monospace, monospace" class="">class Square {</font></div><div class=""><font face="monospace, monospace" class=""> var sideLength: Double = 0.0</font></div><div class=""><font face="monospace, monospace" class=""> var perimeter: Double {</font></div><div class=""><font face="monospace, monospace" class=""> set { </font><span style="font-family: monospace, monospace;" class="">newPerimeter</span><span style="font-family: monospace, monospace;" class=""> in</span></div></div></div></div></div></div><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><font face="monospace, monospace" class=""> sideLength = newPerimeter / 4.0</font></div><div class=""><font face="monospace, monospace" class=""> }</font></div><div class=""><font face="monospace, monospace" class=""> }</font></div><div class=""><font face="monospace, monospace" class="">}</font></div></div></div></div></div></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="">As this would be more consistent with anonymous closure arguments, rather than using newValue which is arbitrary. I’ve never encountered an occasion where I’ve needed a custom name, and I only use external vs internal names on functions where I can make an external name that flows better, but perhaps doesn’t mesh with my other internal variable names.</div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 6 May 2016, at 12:09, Ian Partridge 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 dir="ltr" class=""><div class=""><div class="">Currently, the syntax for explicitly naming property setters is:</div><div class=""><br class=""></div><div class=""><font face="monospace, monospace" class="">class Square {</font></div><div class=""><font face="monospace, monospace" class=""> var sideLength: Double = 0.0</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class=""> var perimeter: Double {</font></div><div class=""><font face="monospace, monospace" class=""> get {</font></div><div class=""><font face="monospace, monospace" class=""> return sideLength * 4.0</font></div><div class=""><font face="monospace, monospace" class=""> }</font></div><div class=""><font face="monospace, monospace" class=""> set(newPerimeter) { // declares newPerimeter parameter, "let" not allowed</font></div><div class=""><font face="monospace, monospace" class=""> sideLength = newPerimeter / 4.0</font></div><div class=""><font face="monospace, monospace" class=""> }</font></div><div class=""><font face="monospace, monospace" class=""> }</font></div><div class=""><font face="monospace, monospace" class="">}</font></div><div class=""><br class=""></div><div class="">Compare this with how extraction of associated values from enumerations looks:</div><div class=""><br class=""></div><div class=""><font face="monospace, monospace" class="">enum ServerResponse {</font></div><div class=""><span style="font-family:monospace,monospace" class=""> case Failure(String)</span><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class=""> case Result(Int)</font></div><div class=""><font face="monospace, monospace" class="">}</font></div><div class=""><font face="monospace, monospace" class="">let response = ServerResponse.Result(404)</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class="">switch response {</font></div><div class=""><font face="monospace, monospace" class="">case .Failure(let reason): // let is required here</font></div><div class=""><font face="monospace, monospace" class=""> print(reason)</font></div><div class=""><font face="monospace, monospace" class="">case .Result(let code):</font></div><div class=""><font face="monospace, monospace" class=""> print(code)</font></div><div class=""><font face="monospace, monospace" class="">}</font></div></div><div class=""><br class=""></div><div class="">For consistency, would it be better to allow/require:</div><div class=""><br class=""></div><div class=""><div class=""><font face="monospace, monospace" class="">class Square {</font></div><div class=""><font face="monospace, monospace" class=""> var sideLength: Double = 0.0</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class=""> var perimeter: Double {</font></div><div class=""><span style="font-family:monospace,monospace" class=""> get {</span></div><div class=""><font face="monospace, monospace" class=""> return sideLength * 4.0</font></div><div class=""><font face="monospace, monospace" class=""> }</font></div><div class=""><font face="monospace, monospace" class=""> set(<b class="">let</b> newPerimeter) { // declares newPerimeter parameter</font></div><div class=""><font face="monospace, monospace" class=""> sideLength = newPerimeter / 4.0</font></div><div class=""><font face="monospace, monospace" class=""> }</font></div><div class=""><font face="monospace, monospace" class=""> }</font></div><div class=""><font face="monospace, monospace" class="">}</font></div></div><div class=""><br class=""></div><div class="">The idea would apply to didSet{} and willSet{} too.</div><div class=""><br class=""></div><div class="">-- <br class=""></div><div class="gmail_signature">Ian Partridge<br class=""></div>
<br 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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br 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=""></div></body></html>