<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=""><div class="">Having postfix conditionals for&nbsp;<span style="color: rgb(181, 27, 71); font-family: Menlo; font-size: 11px;" class="">return</span>&nbsp;would be a lot easier to implement than having them everywhere, because you just need to watch for an&nbsp;<span style="color: rgb(181, 27, 71); font-family: Menlo; font-size: 11px;" class="">if</span>&nbsp;or&nbsp;<span style="color: rgb(181, 27, 71); font-family: Menlo; font-size: 11px;" class="">unless</span>&nbsp;after the&nbsp;<span style="color: rgb(181, 27, 71); font-family: Menlo; font-size: 11px;" class="">return</span>. Of course they might come in handy elsewhere, and may even solve the ever-present problem of the unintuitive ternary operator ?:, but that’s a whole different discussion. This proposal is simply about having some syntactic sugar for return statements.</div><div class=""><br class=""></div><div class="">Seeing as this change would be purely additive and adding more keywords to Swift is not really a problem (we can use them as parameter labels etc.), I don’t really see a reason against it.</div><div class=""><br class=""></div><div class="">Using “unless” for this makes sense especially as a postfix. I agree with keeping guard around, but this statement is different from guard in that the code executed if the condition can’t be satisfied is stated before the keyword, which makes it read well.</div><div><br class=""></div><div>In case of the guard statement, you’d need another keyword to make “unless” logical, like <span style="font-family: Menlo; font-size: 11px; color: rgb(181, 27, 71); font-variant-ligatures: no-common-ligatures;" class="">unless</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">&nbsp;foo !=&nbsp;</span><span style="font-family: Menlo; font-size: 11px; color: rgb(181, 27, 71); font-variant-ligatures: no-common-ligatures;" class="">nil</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">&nbsp;</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class=""><font color="#b51b47" class="">inWhichCase</font></span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">&nbsp;{</span><span style="font-family: Menlo; font-size: 11px;" class="">}</span>, which just feels bulky to me.</div><div><br class=""></div><div>Additionally,&nbsp;<span class="" style="font-family: Menlo; font-size: 11px; color: rgb(181, 27, 71);">return</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(181, 27, 71);">nil</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;<span class="" style="color: rgb(181, 27, 71);">guard</span>&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(181, 27, 71);">let</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;thing = things[</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(204, 68, 40);">index</span><span class="" style="font-family: Menlo; font-size: 11px;">]</span>&nbsp;does not read logically to me.</div><div><br class=""></div><div>–Julian</div><div><br class=""></div><div><blockquote type="cite" class=""><div class="">On 04 Aug 2016, at 17:03, David Rönnqvist 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=""><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="">One complication with allowing postfix conditionals for all statements is that it often needs to have an else clause as well (like the ternary operator “?:").</div><div class=""><br class=""></div><div class="">For example, what’s the type of “x” below?</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> x = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> someCriteria()</span></div></div><div class=""><br class=""></div><div class="">And is “y” initialized or not?</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> y: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">y</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">42</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> someCriteria()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">doSomething(with: y)</span></div></div><div class=""><br class=""></div><div class="">I realize that this idea is more about the feature/behavior than the naming, but renaming “guard” to “unless” is one of the commonly rejected proposals.</div><div class=""><a href="https://github.com/apple/swift-evolution/blob/master/commonly_proposed.md" class="">https://github.com/apple/swift-evolution/blob/master/commonly_proposed.md</a></div></div></div></blockquote></div><div><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="">- David</div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 04 Aug 2016, at 16:52, Kurt Werle 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="">Why would you do this just for return statements?&nbsp; Why not do postfix conditionals for all statements (like ruby)?<div class=""><br class=""></div><div class="">I've always liked postfix conditionals, but not enough to suggest them.&nbsp; Mostly I'm curious about limiting the scope to return statements.</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Aug 4, 2016 at 7:31 AM, Christian Kienle via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">+1</div><div class="gmail_extra"><br class=""><div class="gmail_quote"><div class=""><div class="h5">2016-08-04 15:38 GMT+02:00 Julian Dunskus via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span>:<br class=""></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class=""><div class="h5"><div style="word-wrap:break-word" class="">How often have you written something like the following?<div class=""><br class=""></div><div class="">`</div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#b51b47" class="">if</span><span class=""> indexPath.row == </span><span style="color:#7373ff" class="">0</span><span class=""> { </span><span style="color:#b51b47" class="">return</span><span class=""> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#b51b47" class="">guard</span><span class=""> </span><span style="color:#b51b47" class="">let</span><span class=""> thing = things[index] </span><span style="color:#b51b47" class="">else</span><span class=""> { </span><span style="color:#b51b47" class="">return nil</span><span class=""> }</span></div></div><div class="">`</div><div class=""><br class=""></div><div class="">I propose adding some syntactic sugar to make such statements more readable and simple to write:</div><div class=""><br class=""></div><div class="">`</div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#b51b47" class="">return</span><span class=""> </span><span style="color:#b51b47" class="">if</span><span class=""> indexPath.row == </span><span style="color:#7373ff" class="">0</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#b51b47" class="">return</span><span class=""> </span><span style="color:#b51b47" class="">nil</span><span class="">&nbsp;<span style="color:rgb(181,27,71)" class="">unless</span>&nbsp;</span><span style="color:#b51b47" class="">let</span><span class=""> thing = things[</span><span style="color:#cc4428" class="">index</span><span class="">]</span></div></div><div class="">`</div><div class=""><br class=""></div><div class="">I don’t know how easy or hard this would be to implement, but I think it would improve some code significantly.</div><span class=""><font color="#888888" class=""><div class=""><br class=""></div><div class="">–Julian Dunskus</div></font></span></div><br class=""></div></div>_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div data-smartmail="gmail_signature" class=""><div dir="ltr" class=""><font face="arial, helvetica, sans-serif" style="font-size:12.8000001907349px" class="">Mit freundlichen Grüßen</font><div style="font-size:12.8000001907349px" class=""><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div><div style="font-size:12.8000001907349px" class=""><font face="arial, helvetica, sans-serif" class=""><b class="">Christian Kienle</b></font></div><div style="font-size:12.8000001907349px" class=""><font face="arial, helvetica, sans-serif" class="">Mobile Developer</font></div><div style="font-size:12.8000001907349px" class=""><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div><div style="font-size:12.8000001907349px" class=""><font face="arial, helvetica, sans-serif" class=""><b class="">REWE Digital GmbH</b></font></div><div style="font-size:12.8000001907349px" class=""><font face="arial, helvetica, sans-serif" class="">Domstraße 20, 50668 Köln, Büro: Schanzenstr. 6-20, 51063 Köln</font></div><div style="font-size:12.8000001907349px" class=""><font face="arial, helvetica, sans-serif" class="">Geschäftsführer: Dr. Jean-Jacques Michel van Oosten (Vorsitzender), Christoph Eltze, Dr. Johannes Steegmann, Dr. Robert Zores</font></div><div style="font-size:12.8000001907349px" class=""><font face="arial, helvetica, sans-serif" class="">Handelsregister: Amtsgericht Köln (HRB 78670) UST-ID-Nr.: DE 290 605 450</font></div><div style="font-size:12.8000001907349px" class=""><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div><div class=""><font face="arial, helvetica, sans-serif" style="font-size:12.8000001907349px" class="">Telefon: +49&nbsp;</font><font face="arial, helvetica, sans-serif" class="">151 11441782</font></div><div style="font-size:12.8000001907349px" class=""><span style="font-family:arial,helvetica,sans-serif;font-size:12.8000001907349px" class="">E-Mail:&nbsp;</span><a href="mailto:christian.kienle@rewe-digital.com" style="font-family:arial,helvetica,sans-serif;font-size:12.8000001907349px;color:rgb(17,85,204)" target="_blank" class="">christian.kienle@rewe-digital.com</a><br class=""></div><div style="font-size:12.8000001907349px" class=""><font face="arial, helvetica, sans-serif" class="">Internet:&nbsp;<u class=""><a href="http://www.rewe-digital.com/" style="color:rgb(17,85,204)" target="_blank" class="">www.rewe-digital.com</a></u></font></div><div style="font-size:12.8000001907349px" class=""><br class=""></div><div style="font-size:12.8000001907349px" class=""><font face="arial, helvetica, sans-serif" class="">Ein Unternehmen der&nbsp;<b class="">REWE GROUP</b></font></div><div style="font-size:12.8000001907349px" class=""><font face="arial, helvetica, sans-serif" class=""><a href="http://www.rewe-group.com/" style="color:rgb(17,85,204)" target="_blank" class="">http://www.rewe-group.com</a></font></div></div></div>
</div>
<br class="">_______________________________________________<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" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature" data-smartmail="gmail_signature"><a href="mailto:kurt@circlew.org" class="">kurt@CircleW.org</a><br class=""><a href="http://www.circlew.org/kurt/" target="_blank" class="">http://www.CircleW.org/kurt/</a><br class=""></div>
</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=""></body></html>