<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><blockquote type="cite" class=""><div class=""><div class="">From: Dave Abrahams <<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>><br class="">To: Brent Royal-Gordon <<a href="mailto:brent@architechies.com" class="">brent@architechies.com</a>></div></div></blockquote><blockquote type="cite" class=""><br class=""></blockquote><blockquote type="cite" class=""><div class=""><div class=""><blockquote type="cite" class="">While it's great that `compared(to:case:etc.)` is parallel to `compared(to:)`, you don't actually want to *use* anything like `compared(to:)` if you can help it. Think about the clarity at the use site:<br class=""><br class=""> if foo.compared(to: bar, case: .insensitive, locale: .current) == .before { … }<br class=""></blockquote><br class="">Right. We intend to keep the usual comparison operators.<br class=""><br class="">Poor readability of "foo <=> bar == .before" is another reason we think that giving up on "<=>" is no great loss.<br class=""><br class=""><blockquote type="cite" class="">The operands and sense of the comparison are kind of lost in all this garbage. You really want to see `foo < bar` in this code somewhere, but you don't.<br class=""></blockquote><br class="">Yeah, we thought about trying to build a DSL for that, but failed. I think the best possible option would be something like:<br class=""><br class=""> foo.comparison(case: .insensitive, locale: .current) < bar<br class=""><br class="">The biggest problem is that you can build things like<br class=""><br class=""> fu = foo.comparison(case: .insensitive, locale: .current)<br class=""> br = bar.comparison(case: .sensitive)<br class=""> fu < br // what does this mean?<br class=""><br class="">We could even prevent such nonsense from compiling, but the cost in library API surface area is quite large.<br class=""><br class=""><blockquote type="cite" class="">I'm struggling a little with the naming and syntax, but as a general approach, I think we want people to use something more like this:<br class=""><br class=""> if StringOptions(case: .insensitive, locale: .current).compare(foo < bar) { … }<br class=""></blockquote><br class="">Yeah, we can't do that without making <br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let a = foo < bar<br class=""><br class="">ambiguous<br class=""></div></div></blockquote></div><br class=""><div class=""><br class=""></div><div class="">So, cue crazy idea #1, but what about something like this?</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">struct StringComparison {</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let leftHand: String</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let rightHand: String</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let comparison: SortOrder</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var insensitive: Bool {</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>...</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// … etc</font></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">func <(lhs: String, rhs: String) -> StringComparison { // similar for ==, >, etc.</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>return StringComparison(leftHand: lhs, rightHand: rhs, comparison: .before)</font></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><div class=""><br class=""></div></div><div class="">Then:</div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><br class=""></div></blockquote><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if (a < b).insensitive {<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>...<br class=""></font><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div class=""><br class=""></div><div class="">This would fix the ambiguity of:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let a = foo < bar // ‘a' is StringComparison</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if a.insensitive {</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div class=""><br class=""></div><div class="">IMHO, the big problem with this is that the most obvious default case really should fall-through to a boolean value for the comparison struct:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if a < b { // case-sensitive, non-localized compare</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>...</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div></div><div class=""><br class=""></div><div class="">...but I can’t figure out how to make that work without the old BooleanType protocol, maybe someone smarter than I could…</div><div class=""><br class=""></div><div class="">—Karim</div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>