<div dir="ltr">I hate to triple-post, but removing ternary seems similar to the &#39;removing c-style for loops&#39; proposal that was recently accepted: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0007-remove-c-style-for-loops.md">https://github.com/apple/swift-evolution/blob/master/proposals/0007-remove-c-style-for-loops.md</a><div><br></div><div>To quote:</div><div><span style="color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;line-height:25.6px">The C-style </span><code style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;border-radius:3px;color:rgb(51,51,51);background-color:rgba(0,0,0,0.0392157)">for-loop</code><span style="color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;line-height:25.6px"> appears to be a mechanical carry-over from C rather than a genuinely Swift-specific construct. It is rarely used and not very Swift-like.</span><br></div><div><br></div><div>You could say the same thing about ternary. Rarely used; not very Swift-like, conflicting with the use of ? for optionals; seems to be disliked (rationally or irrationally) by many; and in almost all cases you can achieve the same exact thing, but ostensibly more readable, with a few extra lines.</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Dec 15, 2015 at 11:18 AM Dennis Lysenko via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Also, +1 to removing ?: ternary in general. It does not match the atmosphere of Swift. Where you can write:<div><br></div><div>self.x = a ? b : c</div><div>self.y = a ? d : e</div><div>self.z = a ? f : g</div><div><br></div><div>You could just write</div><div><br></div><div>if a {</div><div>  self.x = b</div><div>  self.y = d</div><div>  self.z = f</div><div>} else {</div><div>  self.x = c</div><div>  self.y = e</div><div>  self.z = g</div><div>}</div><div><br></div><div>Now it&#39;s easier to scan for what changes when a is true. With if-expressions, this would scale even better to multiple conditions/declarations.</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Dec 15, 2015 at 11:14 AM Dennis Lysenko &lt;<a href="mailto:dennis.s.lysenko@gmail.com" target="_blank">dennis.s.lysenko@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Can we just have if-expressions and Xcode indent if-statements the way that Ruby style guides suggest?<div><br><div><blockquote type="cite" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex;color:rgb(117,117,117)"><div style="font-family:Helvetica;font-size:12px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco">let x = if y &lt; 0 {</font></span></div><div style="font-family:Helvetica;font-size:12px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco">            z * z - 4</font></span></div><div style="font-family:Helvetica;font-size:12px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco">        } else {</font></span></div><div style="font-family:Helvetica;font-size:12px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco">            8</font></span></div><div style="font-family:Helvetica;font-size:12px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco">        }</font></span></div></blockquote></div><div><br></div><div>Works fantastically well in Ruby, for me. Looks a bit strange to the untrained eye but that went away for me pretty much the first time I wrote one of these. It&#39;s:</div></div><div><br></div><div>- More readable than ternary</div><div>- Not shoehorning complex logic onto one line</div><div>- All indented to the same indentation level</div><div><br></div><div>And we don&#39;t have the 80-char line delimiter or length limit in Swift, with Xcode also using a slightly smaller font size than most other IDEs, so indentation should not be that much of an issue. Admittedly, ruby style dictates two-space indentation which makes this type of code slightly shallower.</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Dec 15, 2015 at 5:34 AM Al Skipp via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On 15 Dec 2015, at 06:41, Paul Ossenbruggen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">Agreed, I was thinking to I really want turn something that was 2 characters into 10 and will I really be happy with that at the end of the day. A properly formatted ternary can be quite easy to read, it is when people get sloppy and try to cram too much into one expression that they get really hard to follow. For example,</span><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div><font color="#222426" face="Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif" size="2"><span style="white-space:pre-wrap">    return (a&lt;b) ? (b&lt;c) ? b : (a&lt;c) ? c : a : (a&lt;c) ? a : (b&lt;c) ? c : b;</span></font></div><font color="#222426" face="Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif" size="2"><span style="white-space:pre-wrap"><br></span></font></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font color="#222426" size="2"><span style="white-space:pre-wrap">If formatted like this becomes easier follow the logic (at least to me):</span></font></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="color:rgb(34,36,38);font-family:Consolas,Menlo,Monaco,&#39;Lucida Console&#39;,&#39;Liberation Mono&#39;,&#39;DejaVu Sans Mono&#39;,&#39;Bitstream Vera Sans Mono&#39;,&#39;Courier New&#39;,monospace,sans-serif;font-size:small;white-space:pre-wrap"><br></span></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco">    return a &lt; b</font></span></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span style="white-space:pre-wrap">        </span>? b &lt; c </font></span></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span style="white-space:pre-wrap">        </span>  ? b </font></span></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco">          : a &lt; c </font></span></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span style="white-space:pre-wrap">        </span>     ? c </font></span></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span style="white-space:pre-wrap">        </span>     : a </font></span></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span style="white-space:pre-wrap">        </span>: a &lt; c </font></span></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span style="white-space:pre-wrap">        </span>  ? a </font></span></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span style="white-space:pre-wrap">        </span>  : b &lt; c  </font></span></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco">             ? c </font></span></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span style="white-space:pre-wrap">        </span>     : b</font></span></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>I’m happy to make use of the ternary operator, but never in a nested fashion. It looks neat and succinct on first glance, but is quite impenetrable to read. I don’t think there’s a way to make such nested expressions easily comprehensible. Nested ‘if/else/then’ expressions will be equally bewildering.</div><div><br></div><div>On a purely stylistic level I think simple, ‘if/then/else’ expressions, would have a more Swift vibe to them than the ternary operator. Well, that would be the case if it didn’t introduce the confusion between expressions and statements.</div><br><blockquote type="cite"><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font color="#222426" size="2"><span style="white-space:pre-wrap">I do still however like the Switch Expressions.</span></font></div></blockquote></div><br><div>I agree. The Switch expression proposal is worth pursuing, it’s something I’d really like to see in the language. One concern I have is that it faces the same dilemma of the ‘if’ expression proposal, that is, how to make the distinction between a statement and an expression unambiguous?</div><div><br></div><div>Here’s a suggestion, it might be terrible (I’ve not had my third cup of tea of the morning yet), but how about a different keyword? I know, I feel guilty for the suggestion already, but here it is:</div><div><br></div><div>switch == statement</div><div>match == expression</div><div><br></div><div>The syntax you (@Paul) have already suggested for the feature wouldn’t change, but instead of ‘switch’, it’d use the ‘match’ keyword for the expression form. Good, bad, terrible? What do people think?</div><div><br></div><div>Al</div><div><br></div><div><br></div><div><br></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=8CZIdLciSFC-2BO5jF-2FiP8qN7dBFsgCUZ50wdTsolcRPci9f4ZptjHU3Ga7zsyDoIWEuhwdxH1Xhxy4Q93rzRbpwO0HvT2WmwEL6rRN1cO7aH6q6MPyqKWuWdK0U6MBIwD4QJ5KKjY4U3YuHZevZDUuw9ehndSOPMuA-2Fi4Dsgq9YUZZxC45Ax5WTwTgx70-2BTtvBjE80KvurZlhzByEfaEFQagzHh1JYCxqdDBh9uXgHo0-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">
</div>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div></blockquote></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=8CZIdLciSFC-2BO5jF-2FiP8qN7dBFsgCUZ50wdTsolcRPf87s-2FUKbS-2F4S9DD1F7ZkgcOcZ3xQDhNSXVn1JXYy8PFtEYxB3stvIS0flEzK5YaxZzllQmlr1dNx3hjdZlLEAqfwAXuIsgqEsEf3QuqxRUZZw-2FV22WXhwcV-2BVBCaiv5xyBMIEY5yeq3u9EBrR44VXGNtFYF1tSxx0hCpos8R5pb6-2BqGme1gWpQuVZpsrCCnEs-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">
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>