[swift-evolution] [Pitch] Change the endIndex value for closed Ranges and Collections

Howard Lovatt howard.lovatt at gmail.com
Thu Mar 24 16:32:14 CDT 2016


Not sure what you are saying?

    for index in empty.indices {
          // never executed
    }

Would still work.

On Friday, 25 March 2016, Dave Abrahams via swift-evolution <
swift-evolution at swift.org> wrote:

>
> on Wed Mar 23 2016, Howard Lovatt <swift-evolution at swift.org
> <javascript:;>> wrote:
>
> > +1 I think it is a good idea to make a collection run from firstIndex to
> > lastIndex inclusively (note name change to match firstElement and
> > lastElement). For an empty collection both firstIndex and lastIndex would
> > be invalid values that would cause both c[c.firstIndex] and
> c.[c,lastIndex]
> > to fail.
>
> That direction is pretty much a nonstarter with me.  There are *many*
> algorithms that are correct for empty collections without any
> special-case testing, as long as you use half-open ranges.  There's no
> reason to make every algorithm that uses indices test for emptiness
> before proceeding.
>
> See also
>
> https://www.quora.com/Why-are-Python-ranges-half-open-exclusive-instead-of-closed-inclusive
> for philosophical background on why most ranges should be half-open.
>
> --
> Dave
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <javascript:;>
> https://lists.swift.org/mailman/listinfo/swift-evolution
>


-- 
-- Howard.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160325/de58e7a7/attachment.html>


More information about the swift-evolution mailing list