<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="">The difference between issuing return embedded in multiple locations to reduce verbosity is actually slightly more than extra verbosity it is actually a different execution path.</div><div class=""><br class=""></div><div class="">In my last example (Scalaish). The last and only expression in the function is the whole match case - it terminates at the end of the function.</div><div class=""><br class=""></div><div class=""><div class=""> def f2(input: Integer) : Integer = {</div><div class=""> input match {</div><div class=""> case _ if input > 10 => 10</div><div class=""> case _ if input < 0 => 0</div><div class=""> case _ => input</div><div class=""> }</div><div class=""> }</div></div><div class=""><br class=""></div>Whereas if you sprinkle in returns as such, you are actually changing the execution path:<div class=""><br class=""></div><div class=""><div class=""> def f2(input: Integer) : Integer = {</div><div class=""> input match {</div><div class=""> case _ if input > 10 => return 10 <— function terminates here</div><div class=""> case _ if input < 0 => return 0 <— function terminates and here</div><div class=""> case _ => return input <— <— function terminates and here</div><div class=""> }</div><div class=""> }</div><div class=""><br class=""></div><div class="">A move towards spaghetti like code.</div><div class=""><br class=""></div><div class="">Now if you were to add an extra expression like using an intermediate value.</div><div class=""><br class=""></div><div class=""><div class=""> def f2(input: Integer) : Integer = {</div><div class=""> <b class=""> let x = </b>input match {</div><div class=""> case _ if input > 10 => 10 // no longer terminates here</div><div class=""> case _ if input < 0 => 0 // no longer terminates here</div><div class=""> case _ => input // no longer terminates here</div><div class=""> }</div><div class=""> <b class="">x /2 // or return x/2</b></div><div class=""> }</div><div class=""><br class=""></div><div class="">You would have had to go back and modify the original execution path with all the embedded returns which can also be a source of unwanted defects if one is missed (in larger functions).</div><div class=""><br class=""></div><div class=""><br class=""></div></div><div><blockquote type="cite" class=""><div class="">On 2015-12-21, at 3:29:27, Radosław Pietruszewski <<a href="mailto:radexpl@gmail.com" class="">radexpl@gmail.com</a>> 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="">I honestly don’t have a problem with having to say `return` inside functions. That’s not necessarily a -1, but I’m reluctant to say +1 when _even I_ don’t really have the problem with extra verbosity.</div><div class=""><br class=""></div><div class="">*However*, as others pointed out, having to type `return` is a bit tiring in the context of a computer property’s “get”:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><blockquote type="cite" class=""><span style="color: rgb(187, 44, 162);" class="">var</span> twiceSomething: <span style="color: rgb(112, 61, 170);" class="">Int</span> { <span style="color: rgb(187, 44, 162);" class="">self</span>.something * <span style="color: rgb(39, 42, 216);" class="">2</span> }</blockquote></div></div><br class=""><div class="">
<div class="">— Radek</div>
</div>
<br class=""><div class=""><blockquote type="cite" class=""><div class="">On 19 Dec 2015, at 14:30, Craig Cruden 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=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" 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="">When writing short functional code in a function it would be nice if the return keyword were an optional keyword. </div><div class=""><br class=""></div><div class="">Just return the last evaluated expression.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">i.e.</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="">func</span> flipFunc<T, U>(arg1: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span>, arg2: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">U</span>) -> (<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">U</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span>) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> (arg2, arg1)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">The keyword return would still be there for breaking out of a function.</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=4hhvaxvZNsLrnZM9llg93kxoqfFYC8lhv8HAehOIDqIIX-2BB9R8E1jk2QPl4GDWf1csw0oIX0kbMf471D6Iu6nP8tdKIqzYwLCOE9dPklFiN-2BxwiaJD8g2RGSNaVoz1o9DQwiTZ0AjOYfq-2FkeIvejq27DyFs079lahlQmBrf4hPf129SvHS3rKeLPM1BBjAfofGsgGs-2FeqwaHHJBB-2BfAOag52KrJ1Y5wsOujheg-2Fm0vs-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>
_______________________________________________<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></div></blockquote></div><br class=""></div></body></html>