<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="">There’s no need for the “then" keyword if you just allow if-expressions as well.<div class=""><br class=""></div><div class="">```</div><div class="">let result = if condition { 1 } else { 2 }</div><div class="">```</div><div class=""><br class=""></div><div class="">Or more verbosely:</div><div class=""><br class=""></div><div class=""><div class="">```</div><div class="">let result =</div><div class=""> if condition {</div><div class=""> return 1</div><div class=""> }</div><div class=""> else {</div><div class=""> return 2</div><div class=""> }</div><div class="">```</div></div><div class=""><br class=""></div><div class="">The same could be for switch statements as well.</div><div class=""><br class=""></div><div class="">```</div><div class="">let result = switch item {</div><div class=""> case foo: 1</div><div class=""> case bar: 2</div><div class="">}</div><div class="">```</div><div class=""><br class=""></div><div class="">The above assume implicit returns on single-line statements on the condition/case branches.</div><div class=""><br class=""></div><div class="">-David</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 3, 2015, at 11:26 PM, David Hart <<a href="mailto:david@hartbit.com" class="">david@hartbit.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="">I also tend to agree but I don't like the ordering in the Python version and would rather see the introduction of the then keyword<br class=""></div><div class=""><br class="">On 04 Dec 2015, at 06:08, Sean Heber <<a href="mailto:sean@fifthace.com" class="">sean@fifthace.com</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div class="">I agree that using ? for ternary feels.. uncomfortable in Swift. I wouldn't mind seeing Python-style or just eliminating it entirely in favor of simplicity.</div><div class=""><br class=""></div><div class="">l8r</div><div class="">Sean<br class=""></div><div class=""><br class="">On Dec 3, 2015, at 10:48 PM, Dan Appel <<a href="mailto:dan.appel00@gmail.com" class="">dan.appel00@gmail.com</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><span class=""><div id="bloop_customfont" style="font-family: Helvetica, Arial; margin: 0px;" class="">I agree that ternary can make code unreadable, especially so with the ‘?’. I personally like the Haskel option the most, but it introduces a new keyword ‘then’, which isn’t great either. Python’s "y if x else z" is therefore, in my opinion, the best alternative.</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; margin: 0px;" class="">Also, I found it interesting how split the Rust community was about removing the ternary operator.</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; margin: 0px;" class=""><span style="font-family:helvetica,arial" class="">— </span></div><div id="bloop_sign_1449203852020918016" class="bloop_sign" style="font-family: Helvetica, Arial;"><div style="font-family:helvetica,arial" class="">Dan Appel</div></div></span></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Thu, Dec 3, 2015 at 7:58 PM J. Cheyo Jimenez <<a href="mailto:cheyo@masters3d.com" class="">cheyo@masters3d.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><span style="font-size:12.8px" class="">Would you consider replacing the C style ?: ternary operator to something that does not use the question mark and colon ? </span><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">The use of "?" can be confusing when speed reading code with optionals. </div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">Consider this code as somebody learning swift as their first language.</div><div style="font-size:12.8px" class=""><p class=""><font face="monospace, monospace" class="">let result = !condition ? 1 : 2</font></p></div><div style="font-size:12.8px" class=""><br class=""></div><div style="font-size:12.8px" class="">Some alternatives:</div><div style="font-size:12.8px" class=""><div class=""><br class=""></div><div class="">Haskel <div class=""><div dir="ltr" style="direction:ltr;color:rgb(37,37,37);font-family:sans-serif;font-size:14px;line-height:14.9333px;background:rgb(248,248,248)" class=""><pre style="white-space: pre-wrap; font-family: monospace, Courier; border: 1px solid rgb(221, 221, 221); padding: 1em; line-height: 1.3em; background-color: rgb(249, 249, 249);" class=""><span style="color:rgb(0,128,0);font-weight:bold" class="">if</span> predicate <span style="color:rgb(0,128,0);font-weight:bold" class="">then</span> expr1 <span style="color:rgb(0,128,0);font-weight:bold" class="">else</span> expr2</pre></div><div class="">Python</div></div><div class=""><pre style="white-space: pre-wrap; font-family: monospace, Courier; border: 1px solid rgb(221, 221, 221); padding: 1em; line-height: 1.3em; font-size: 14px; background-color: rgb(249, 249, 249);" class="">result <span style="color:rgb(102,102,102)" class="">=</span> x <span style="color:rgb(0,128,0);font-weight:bold" class="">if</span> a <span style="color:rgb(102,102,102)" class="">></span> b <span style="color:rgb(0,128,0);font-weight:bold" class="">else</span> y</pre></div><div class="">The advantage of not using the question mark is that the language will be more consistency on the use of "?" to mean only optionals. <br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">References:</div><div class=""><a href="https://devforums.apple.com/message/1020139#1020139" target="_blank" class="">https://devforums.apple.com/message/1020139#1020139</a></div></div></div><div style="font-size:12.8px" class=""><a href="https://github.com/rust-lang/rust/issues/1698#issuecomment-3705066" target="_blank" class="">https://github.com/rust-lang/rust/issues/1698#issuecomment-3705066</a></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=4Q3dO0ELn940F2HNV6NWP3n6-2BFmLgXvEeytAtbr-2BgeDYoD5tpBTS72h2nPdoesBjFIHECaHIxYh10FYCXUeWQ65fPIrQZyTNAdleeXCQ64naCq-2BRo4e2zXf0J9A2HRmL88OFXVfBZ5quTXBpurvrqBBs4d-2ByKIvlmbh88TYRH4UfeDBg9-2Fm70jQ1K-2FTBCibgE3e1ZTsN44r9UpWEyJfJ-2F3E-2Fhz7mL2i3piK7DxnoOdI-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="">
_______________________________________________<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="">
</blockquote></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=CzM39owGTpkJ1zyGXnrRVEXja65D5KHvjV3-2BNib8-2FALErD0kiUUIMIXRwdeL5Lu76KgH2bdx5yKs2bSajEksH7zgA3iXmq0rXx62UiivBwrhmvKJ2lmUUvw-2F1goy53ob9w0N-2B043Vqbsv4aPVvPG12sD1tuiB1iZXAJIXUr6PdM3alK-2Fg1QSW0tRJlIaq-2BL1Q9kmi4L-2BquSs5eiGROE3kA45gCSlnV2ljaEzqH8fWPY-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>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=nE9rxSXA5G4kxsTVkgv43hXwizS3O2z60WweqomIrdhDQaJFFM-2BMbJRHzRQnffAg0Zt6UaycrX12nXLIZFiAgcLjU96ZfPh5dRJBCSLNILhlCY95BzqlLpT6pX-2B9q7BavrJVjkYQtQI38LVaaIEPfHKkmPYmu-2BtgwQR1qa66zWTe-2F7Q0MsLc7ADrUiJGrsP6zzDHna2ucVlAZJoSk2u7ptKO4FK165xJajrxeQxQvsc-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>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=nE9rxSXA5G4kxsTVkgv43pXkLx-2B36P-2BPNJufHeY0dgdbCp-2BWhOxq3PDIqAyBYGQ0kWPIv4qdll8LAWoMYQohnn8bX9mxOk66coEw-2BVuBTnfhBCE7N-2F1T9j789Fs67-2B58xtO1h8BuRMQ5TtQwKT-2BziG5ru-2BiDm1e-2BSp1mX1XSS-2Bp0mysLuGuXiX-2Fhs0d3dR4zu-2FJz6AVTM9YM1DEFFjHlGt14zP6FQEo9nmigiuSR8Jc-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="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>