<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>I think all of this could be solved by just having postfix if statements</div><div><br></div><div>var str: String?</div><div><br></div><div>str = "hot" if state == .Hot</div><div>str = "cold" if state == .Cold</div><div><br></div><div>//if the ??= operator proposal is accepted then we could just do:</div><div>str ??= "Invalid Temperature"</div><div><br></div><div><br></div><div>This is used a lot in Ruby, more flexible since it could be used on any line of code, flexible and concise. I think it reads quite well so beginners will grasp it easily (as I did when writing my first Ruby)</div><div><br></div><div>I think compiler wise it could be treated like a do while loop except it only loops once ;)&nbsp;</div><div><br><div>Sent from my iPhone</div></div><div><br>On 29 Jan 2016, at 08:06, Charles Constant via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div>Sorry for the barrage here, Paul :)</div><div><br></div><div><span style="font-size:13px">&gt; I’m not even convinced the new syntax is clearer so much as cleverer.</span><br></div><div><br></div>As I've followed the various threads for switch-like assignments, I've been thinking a lot about how valid it is to say that more explicit is all that helpful to beginners. I wish I had the resources to test these assumptions with actual people who had never written Swift.<br><div><br></div><div>As an example.&nbsp;</div><div><br></div><div>We assume that this:</div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(35,35,35)">&nbsp; &nbsp;&nbsp;<span style="color:rgb(50,62,125)">let</span>&nbsp;phrase:&nbsp;<span style="color:rgb(88,126,168)">String</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(88,126,168)"><span style="color:rgb(35,35,35)">&nbsp; &nbsp;&nbsp;</span><span style="color:rgb(50,62,125)">switch</span><span style="color:rgb(35,35,35)">(&nbsp;</span>temperature&nbsp;<span style="color:rgb(35,35,35)">) {</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(80,13,80)">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(50,62,125)">case</span>&nbsp;.Cold:&nbsp;<span style="color:rgb(88,126,168)">str</span>&nbsp;=&nbsp;<span style="color:rgb(132,62,100)">"Too cold"</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(80,13,80)">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(50,62,125)">case</span>&nbsp;.Hot:&nbsp;&nbsp;<span style="color:rgb(88,126,168)">str</span>&nbsp;=&nbsp;<span style="color:rgb(132,62,100)">"Too hot"</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(80,13,80)">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(50,62,125)">default</span>:&nbsp; &nbsp;&nbsp;<span style="color:rgb(88,126,168)">str</span>&nbsp;=&nbsp;<span style="color:rgb(132,62,100)">"Just right"</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(80,13,80)">&nbsp; &nbsp; }</p></div><div><br></div><div>is going to be easier for beginners than something like this:</div><div><br></div><div>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(35,35,35)">&nbsp; &nbsp;&nbsp;<span style="color:rgb(50,62,125)">let</span> phrase = <span style="color:rgb(88,126,168)">temperature</span> ?</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(80,13,80)">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:rgb(132,62,100)">"Too cold" </span><span style="color:rgb(35,35,35)">if </span>.Cold :</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(80,13,80)">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:rgb(132,62,100)">"Too hot” </span><span style="color:rgb(35,35,35)">if</span><span style="color:rgb(132,62,100)"> </span>.Hot :</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(132,62,100)"><span style="color:rgb(80,13,80)">&nbsp; &nbsp; &nbsp; &nbsp; </span>"Just right" <span style="color:rgb(35,35,35)">if _ </span><span style="color:rgb(80,13,80)">&nbsp;</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(80,13,80);min-height:13px"><br></p></div><div><div>I'm using a short version here that is not the actual proposal, and that we won't use (since we don't want to overload "if"). But I have a strong hunch that a beginner is not going to find the longer version any more clear. There's a lot of syntax for the programmer to parse in the "switch" statement, as it stands. I suspect the less redundancy we have, the easier it is to figure out what is going on.</div></div><div><br></div><div><br></div></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>