[swift-users] Why does Array subscript fail at runtime?
owenzx at gmail.com
Wed Jul 20 23:50:31 CDT 2016
For Array, it is easy to know its boundary. And it is an error when
accessing indices out of the boundary. Returning a nil makes your app hard
to trace bugs.
Array's subscript function returns Element instead of Element?. It is
common and aligns with the other languages. You question seems odd to me.
On Thu, Jul 21, 2016 at 12:07 PM, H. Kofi Gumbs via swift-users <
swift-users at 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?
> swift-users mailing list
> swift-users at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-users