<div dir="ltr">Thank you Paul for the initial draft. <div><br></div><div>Here is the a draft version that I intend to submit. <br><div><br></div><div><a href="https://github.com/masters3d/swift-evolution/blob/ReplaceTernary/proposals/00-Replace%20%3F:%20Ternary%20Operator%20with%20if-then-else%20expression.md">https://github.com/masters3d/swift-evolution/blob/ReplaceTernary/proposals/00-Replace%20%3F:%20Ternary%20Operator%20with%20if-then-else%20expression.md</a><br><br>On Monday, December 14, 2015, Paul Ossenbruggen via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word">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,<div><br></div><div><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<b) ? (b<c) ? b : (a<c) ? c : a : (a<c) ? a : (b<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><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><span style="color:rgb(34,36,38);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;font-size:small;white-space:pre-wrap"><br></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"> return a < b</font></span></div><div><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 < c </font></span></div><div><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><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"> : a < c </font></span></div><div><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><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><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 < c </font></span></div><div><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><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 < c </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"> ? c </font></span></div><div><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><br></div><div><font color="#222426" size="2"><span style="white-space:pre-wrap">Is this new syntax helping?<br></span></font><br></div><div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"> return if a < b </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span>then if b < c </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span> then b </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"> else if a < c </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span> then c </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span> else a </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span>else if a < c </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span> then a </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span> else if b < c </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"> then c </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span> else b</font></span></div></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><br></font></span></div><div><font color="#222426" size="2"><span style="white-space:pre-wrap">I found this translation quite tricky to do. maybe parens help?</span></font></div><div><font color="#222426" face="Monaco" size="2"><span style="white-space:pre-wrap"><br></span></font></div><div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"> return (if a < b </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span>then (if b < c </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span> then b </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"> else (if a < c </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span> then c </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span> else a)</font></span><span style="font-family:Monaco;color:rgb(34,36,38);font-size:small;white-space:pre-wrap">)</span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span>else (if a < c </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span> then a </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span> else (if b < c </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"> then c </font></span></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><span>        </span> else b))</font></span><span style="font-family:Monaco;color:rgb(34,36,38);font-size:small;white-space:pre-wrap">)</span></div></div><div><span style="color:rgb(34,36,38);font-size:small;white-space:pre-wrap"><font face="Monaco"><br></font></span></div><div><font color="#222426" size="2"><span style="white-space:pre-wrap">Not really and I still I found this hugely frustrating, so much so that I am going to drop all support for this proposal and remove my name from it. If anyone wants to take over feel free. </span></font></div><div><span style="white-space:pre-wrap;color:rgb(34,36,38);font-size:small"><br></span></div><div><span style="white-space:pre-wrap;color:rgb(34,36,38);font-size:small">Others still keen on the idea should try this experiment. It convinced me is horrible idea :-) I don’t want to be blamed for it by every Swift programmer in the future. </span></div><div><font color="#222426" size="2"><span style="white-space:pre-wrap"><br></span></font></div><div><font color="#222426" size="2"><span style="white-space:pre-wrap">I do still however like the Swift Expressions.</span></font></div><div><font color="#222426" face="Monaco" size="2"><span style="white-space:pre-wrap"><br></span></font></div><div><font color="#222426" face="Monaco" size="2"><span style="white-space:pre-wrap">- Paul</span></font></div><div><font color="#222426" face="Monaco" size="2"><span style="white-space:pre-wrap"><br></span></font></div><div><font color="#222426" face="Monaco" size="2"><span style="white-space:pre-wrap"><br></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"></font><div><div><div><blockquote type="cite"><div><br></div><div>On Dec 14, 2015, at 4:50 PM, Nick Shelley via swift-evolution <<a>swift-evolution@swift.org</a>> wrote:</div><br><div><div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="font-size:12.8px">I however frequently hear people saying ternary should be avoided because they are hard to read or they hate them.</span></blockquote><div><br></div><div>FWIW, I used to be one of those people, but then started working on a team where one member liked them. He didn't force them on us, but after enough code reviews where he showed us how to turn 5-line if/else statements into simple one-line ternary expressions, I got used to reading them and now love them and use them often.</div><div><br></div><div>People also hate map, flatMap, reduce, etc., for the same reasons (it's hard for them to read because it's not the for loop they're used to). I think it's a simple matter of getting used to it.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 14, 2015 at 11:57 AM, Chris Lattner via swift-evolution <span dir="ltr"><<a>swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><span><br><div><blockquote type="cite"><div>On Dec 14, 2015, at 12:19 AM, Paul Ossenbruggen via swift-evolution <<a>swift-evolution@swift.org</a>> wrote:</div><br><div><div style="word-wrap:break-word">Once again, thank you for all the feedback, if I sound in anyway grumpy in responding to any email, it has a bit more to do with my cold than the suggestions.<div><br></div><div>I have split the original proposal into two proposals and incorporated a bunch of feedback. Splitting it up has been extremely good, not only does it improve readability, I am actually finding I could take or leave the ternary replacement idea. But the proposal will be there if enough everyone thinks it is a good idea. We could put it to a vote to see if there is enough interest and I would be happy to take it further if there is. I suspect this thread would not exist at all if there was no interest in it. However, I am finding I am far more interested in getting switch expressions. <div><div><br></div><div>Ternary Replacement</div><div><a href="https://github.com/possen/swift-evolution/blob/master/0021.md" target="_blank">https://github.com/possen/swift-evolution/blob/master/0021.md</a></div></div></div></div></div></blockquote><br></div></span><div>Quick comment. The proposal states:</div><div><br></div><div><br></div><div>Is it really better? Why not just keep ternary expressions?<br>This is a valid question, there is an advantage in compactness to ternary expressions. I however frequently hear people saying ternary should be avoided because they are hard to read or they hate them. There seems to many who either stronly dislike it or don't care.</div><div><br></div><div><br></div><div>However, it doesn’t actually show that it is solving the objections people have to the ternary operator. It is true that some people find the ?: syntax weird, but an equal number of people say that the problem is that you’re putting complex conditional logic inline into the middle of an expression - this proposal actually makes that objection worse. There are also other objections to ?:, and until you enumerate them, it is hard to see whether this proposal is making things better or worse.</div><div><br></div><div>-Chris</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=Kyo40-2Fb6mK7qqe0u18o4nlmNW45gwtJGUNOsveb6UxMCKU0IxM3AL-2BXB69-2BTeBzqeiHEjxCbGiiTkOy7TeYvpqYPlzaY54wmpuRZO1P8gRoZmxxWLqoqzHkADbbxA8c5rtsQQk4-2Fu7fXEu4WagpNp-2BomNvCIawTMV5yfsYmUNV-2FP44VHctms-2FBjaa-2FVsTHCWfhMLUdui5GKu7Q7-2BIYa8rNI2wUC9BB77lcZvEScfTLI-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;">
</div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a>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>
<br></blockquote></div><br></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=emrIhnP1hIf76Foxxv4NNJQX-2FWhcznESwKBSwD1MEwxd0PytJAmY2hR14bdjNHx9PC60KNdBJshimtPsRB3ib-2FN1Tg-2FC9bwRbKYjGsXy4tXXJstbA-2FoRw8e2aYVMq4yzoH-2FeJcfr-2BKiJLFc-2FTstD6N4YvDirL8AEKeS3DuridwsigHaRLD-2BQ56YhyMuQdgianGfqc-2BvZdwzB4GqnwLVr-2Fw-3D-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;">
_______________________________________________<br>swift-evolution mailing list<br><a>swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=OWK4tSasaK2n-2FQIIcS9Ug-2FuFXG-2BJ3z6cFMLgm306hDexgmscs6xC-2FBg0NtqgxvKcEUWmNi3olYxonqodb-2FTuI9u-2F3zcQSSvqxtTKqwPkK6v4OpsrgRvcRudWIVh8dijj7JpwBWpikI96hlFZgyg3-2B0WrU-2FKIkXuOnBaekY0Ivo9BWsZL5wPURtVC-2BoCffsXXi1omqhBPPsEH0XRWKmc-2FpFktUyu3SQFSwnQrQSIDn9Q-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;">
</div>
</blockquote>
</div></div></div>