<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 9, 2018, at 2:12 AM, Jonathan Hull via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">- Why bother supporting non-closed Ranges at all? &nbsp;If you only allow closed ranges, then you can’t end up with an empty range. The only difference in behavior I can think of is on floating point, but I can’t think of a use-case where excluding the supremum is actually useful in any real world way.</div><br class="Apple-interchange-newline"></div></blockquote></div><div class=""><br class=""></div><div class="">Ranges are the currency type, whereas closed ranges aren’t. We should try to avoid any solution that goes against this pattern. People are going to have a Range, and having to convert it into a ClosedRange just to get a random number from it is confusing.</div><br class=""><div class="">The argument goes that you want to avoid traps, therefore forbid half-open range because it can be empty and might trap, whereas closed ranges doesn’t. Therefore, let’s only have closed ranges. Type safety ftw.&nbsp;</div><div class=""><br class=""></div><div class="">In practice, I don’t think this is justified. Realistically, you can divide uses into two cases, literals and runtime-generated ranges.</div><div class=""><br class=""></div><div class="">Literals are obviously empty by inspection. It’s hard to do this by accident and any kind of coverage testing of (0..&lt;0).random() will immediately trap. So probably a non-issue.</div><div class=""><br class=""></div><div class="">If you’re generating ranges at runtime from variables, you have another risk of traps that applies just as much to closed ranges: inversion.</div><div class=""><br class=""></div><div class="">i.e.:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">x = <span style="color: #272ad8" class="">5</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">y = <span style="color: #272ad8" class="">4</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">x...y </span>// boom, can't form Range with upperBound &lt; lowerBound</div></div><div class=""><br class=""></div><div class="">This is easily done. Nate’s example playground even had a possible case!</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class="">// better hope items always has at least 3 elements...</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">let</span> countForSale = (<span style="color: #272ad8" class="">3</span>...<span style="color: #4f8187" class="">items</span>.<span style="color: #703daa" class="">count</span>).random()&nbsp;</div></div><div class=""><br class=""></div><div class="">Given this is already an issue, the additional risk of trapping on empty half-open ranges seems modest and acceptable to me, compared to the alternative of encouraging constant banging of the result from&nbsp;<span style="font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">.random()</span>&nbsp;on ranges.</div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>