<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="">I’m wondering what the actual use of this is. Why not just write:<div class=""><br class=""></div><div class=""><font face="Courier New" class="">class Foo {</font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>init(x: Double) {</font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>self.x = x</font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var x: Double</font></div><div class=""><font face="Courier New" class="">}</font></div><div class=""><br class=""></div><div class=""><br class=""><div class="">
Regards,<div class=""><br class=""></div><div class="">Nicky</div>

</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On 11 dec. 2015, at 20:20, Nathan Yee via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Certain languages allow the programmer to avoid creating backing variables for getters and setters by using this syntax:<br class=""><br class="">class Foo {<br class="">&nbsp;&nbsp;&nbsp; init(x: Double) {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.x = x<br class="">&nbsp;&nbsp;&nbsp; }<br class="">&nbsp;&nbsp;&nbsp; var x: Double {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set<br class="">&nbsp;&nbsp;&nbsp; }<br class=""><div class="">&nbsp;&nbsp;&nbsp; // alternatively var x: Double { get; set }<br class=""></div>}<br class=""><br class=""><div class="">and generating code equivalent to this:<br class=""></div><div class=""><br class="">class Foo {<br class="">&nbsp;&nbsp;&nbsp; init(x: Double) {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _x = x<br class="">&nbsp;&nbsp;&nbsp; }<br class="">&nbsp;&nbsp;&nbsp; var _x: Double<br class="">&nbsp;&nbsp;&nbsp; var x: Double {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return _x<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _x = newValue<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br class="">&nbsp;&nbsp;&nbsp; }<br class="">}<br class=""><br class=""></div><div class="">This notation decreases verbosity and reduces the chance of incorrectly implementing the pattern.<br class=""><br class=""></div><div class="">In the following case, the computed property 'x' can only be set in the initializer.<br class=""><br class="">class Foo {<br class="">&nbsp;&nbsp;&nbsp; init(x: Double) {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.x = x<br class="">&nbsp;&nbsp;&nbsp; }<br class="">&nbsp;&nbsp;&nbsp; var x: Double { get }<br class="">}<br class=""><br class=""></div><div class="">Alternatively, the following syntax can be used to avoid using an initializer:<br class=""><br class="">class Foo {<br class="">&nbsp;&nbsp;&nbsp; var x: Double { get } = 1.0<br class="">}</div><div class=""><br class=""></div><div class="">Before looking into the nuances of this syntax (regarding struct/enum properties, access control, attributes, etc.) I would like to ask the community if this feature would be a good fit for Swift.<br clear="all" class=""></div><div class=""><br class="">-- <br class=""><div class="gmail_signature">Nathan<br class=""></div>
</div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=RHl2la-2BftHBRgU0PDt5l8enF-2FEQjC5JypuWCzFZiX9R5XopMaGpIYITFFrg-2BgjsEFsrGwm5IB8ihKaD-2FL-2FwsQ-2FMiDXlOE83YJPhB895Hb2CRSIbjH3r4T8x-2F0dP0ohuIeLlzwFOu25i6bQ9-2FXhss1HsC7Rh2qNdluqdndLW2hX9VbLqhR-2F3Sno74AMoJ4EAc6KoRYn7qlkECCl-2BvnTAPViaC-2FOystJDYXXDIEyQKqGU-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="">
_______________________________________________<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>