If I’m not mistaken, the main reason for Swift arrays being unsafe in this way is for performance. Checking each subscript would be expensive in a large loop; it’s much more performant to loop from the array’s start index to its end index.
Jeff Kelley slauncha...@gmail.com | @SlaunchaMan <https://twitter.com/SlaunchaMan> | jeffkelley.org <http://jeffkelley.org/> > On Jul 20, 2016, at 9:07 PM, H. Kofi Gumbs via swift-users > <swift-users@swift.org> wrote: > > Hello Swift community, > > Here's a philosophy I've struggled with since I started learning Swift. In > general, it seems that failable function calls return `Optional`s; however, > `Array`s violate this rule by failing fast at runtime. I understand that > subscripts can't throw, so the only way to fail fast is to do so at runtime. > I also realize that there are many implementations of the `array[safe: > index]` that I could choose to use instead. However, I do not understand why > the default behavior is still to fail at runtime. Especially given how they > are often introduced as a beginner-friendly data structure. Am I missing some > language philosophy or major decision? > > Thanks > _______________________________________________ > swift-users mailing list > swift-users@swift.org > https://lists.swift.org/mailman/listinfo/swift-users
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users