<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="">Yeah, I attributed adding “then” to statements to you but I added that it not be required. I did not want it to be required both because personally I like just putting the brace after the conditional, it not necessary in the statement form, and where possible I like to avoid visual clutter as much as possible. The benefit to new users is that don’t need to worry about when to use then. This helps with the consistency of the two forms and what current Swift users are used to. Also, it does not break existing code. <div class=""><br class=""></div><div class=""><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 14, 2015, at 8:24 AM, Thorsten Seitz <<a href="mailto:tseitz42@icloud.com" class="">tseitz42@icloud.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class=""></div><div class="">I think there's been a misunderstanding or two...</div><div class=""><br class=""></div><div class="">First I proposed that if if-expressions would be written with "then" then if-statements should use "then", too, for consistency. Always, not optionally.</div><div class=""><br class=""></div><div class="">Second I would require if-expressions to always have an "else" clause (as opposed to proposals that suggested to interpret missing "else" clauses as "else nil", i.e making the result type of the if-expression optional).</div><div class=""><br class=""></div><div class="">-Thorsten</div><div class=""><br class="">Am 13.12.2015 um 20:50 schrieb J. Cheyo Jimenez via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class=""><font size="2" class=""><span style="background-color:rgba(255,255,255,0)" class="">"or we could go with an optional “then” for statements as was suggested by Thorsten. "<br class=""></span></font></div><div class=""><font size="2" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></font></div><div class=""><font size="2" class=""><span style="background-color:rgba(255,255,255,0)" class="">I don't think this should go in the proposal. An else is alway required in a guard statement, an expression should not return an optional imho.</span></font></div><div class=""><font size="2" class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></font></div><br class=""><br class="">On Sunday, December 13, 2015, Paul Ossenbruggen via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><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=""><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 13, 2015, at 8:11 AM, Jakob Egger <<a href="javascript:_e(%7B%7D,'cvml','jakob@eggerapps.at');" target="_blank" class="">jakob@eggerapps.at</a>> wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class="">I really don't like the "if cond then expr1 else expr2".<div class=""><br class=""></div><div class="">1) First of all, it's extremely verbose. It's almost as bad as the SQL construct "case when cond then expr1 else expr2 end”.</div></div></div></blockquote><div class=""><br class=""></div>Yeah it adds a few characters overall. What used to be 2 chars now takes 10. Clarity is preferred though by many. I head frequently people telling users to never use ternary operators because they are confusing to read. </div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><div class=""><br class=""></div><div class="">2) It makes Swift harder to learn. Newcomers will be confused why you sometimes need to use curly braces and why at other times you need to use the "then" keyword.</div></div></div></div></blockquote><div class=""><br class=""></div>I did mention this in Alternatives Considered section. By making the else part required, this emphasizes that it is different or we could go with an optional “then” for statements as was suggested by Thorsten. <br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><div class=""><br class=""></div><div class="">3) It doesn't help when you want to do multi-line calculations</div></div></div></div></blockquote><div class=""><br class=""></div>This is the case with the ternary as well, I think it is better to keep it simple. <br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><div class=""><br class=""></div><div class="">But there is one good side to this proposal: it nests more naturally than the ternary operator:</div><div class="">"if cond then expr1 else if cond2 then expr2 else expr3"</div><div class="">vs.</div><div class="">"cond ? expr1 : (cond2 ? expr2 : expr3)</div><div class=""><br class=""></div><div class="">The proposed syntax for the switch statement is so confusing that I really don't think it is a good idea.</div></div></div></div></blockquote><div class=""><br class=""></div>Not sure why that is, it is essentially the same as the existing switch statement except everything is an expression instead of statements. Is there anything I can do in the examples or documentation to make things clearer?</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><div class=""><br class=""></div><div class="">Why not just allow normal if statements to return values?</div><div class="">I don't see what's so bad about the following:</div><div class="">"let value = if cond {expr1} else {expr2}"</div><div class=""><br class=""></div><div class="">This would also extend to multiple lines:</div><div class="">let value = if cond {</div><div class=""> expr1</div><div class="">} else {</div><div class=""> let something = Object()</div><div class=""> something.doStuff()</div><div class=""> something</div><div class="">}</div><div class=""><br class=""></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">I answered this with others, also notice how there are braces everywhere? does that really work when you just want to put something on one line. What happens when one of your branches returns void? Expressions are guaranteed to have a result, statements don’t make such a guarantee. </div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><div class="">Jakob</div><div class=""><br class=""></div><div class=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">On 13 Dec 2015, at 06:54, Paul Ossenbruggen via swift-evolution <<a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">Hello All, </div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class=""></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">Been sick in bed all day, but decided to try to be productive…</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class=""></div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">I did a rough draft of a proposal for implementing if expressions and switch expressions based upon the discussions we had here. I have tried to keep the scope of the changes as small as possible, only added one keyword and kept things as similar to the existing language constructs as possible. If anyone wants to help me with this, or has feedback, please let me know,</span><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class=""></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><a href="https://github.com/possen/swift-evolution/blob/master/0020.md" target="_blank" class="">https://github.com/possen/swift-evolution/blob/master/0020.md</a></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class=""></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">Thanks,</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">- Paul</div></div></blockquote></div><br class=""></div></div></div></div></div></blockquote></div><br class="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=OWK4tSasaK2n-2FQIIcS9Ug-2FuFXG-2BJ3z6cFMLgm306hDd2K7aMKEWzFtc7f-2FVKkYcqZP18VTj1oID2ndbURM9lg7fQb-2FpYexkd8y2UlaLbsxm8AzFcoIb6nelAl5qLeuid9ukfMYxzj06VeOSn4ftmlPFDV-2B-2BRur6qY0N6LRCXtUaYv3sR-2Friie8HPVU-2FXvK5CBmE-2BJHUW6NT8babQS9iY8FavXEbnHfy-2BnM3HTYp8Low-3D" alt="" width="1" height="1" border="0" style="min-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>
</blockquote>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1MXK54sosN3xru3iYcLt0oBZ2w20i49gyogXctgrspeO1vcNJUE9Z-2BgsjFiOesYSzEMohS-2BYkBSAoIQgopbP7w2N8MCFEe3-2BOGIpsjQug1OY1rgA-2FXDvpyLAABSS11Fi-2FQhXnhtQZgsm5pQq4JOnKBb2KE0IbniylPj0Pxhf54MNMYubHM-2FPu45m9OX3o79hde49HFF3PfQLFxGynx7G7mSJRRvvFzwq9CE-2FHYrDDJY-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></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></div></div></blockquote></div><br class=""></div></div></body></html>