<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 23, 2016, at 4:52 PM, Andreas Ley 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class="">"..*most* people don’t expect.." could you prove this please?</blockquote><div class=""><br class=""></div><div class="">I should have written “most people I know” or “the people I work with".</div><div class=""><br class=""></div><blockquote type="cite" class="">Especially if they know a little of C language or other language that don't allow to use wrong indexes for arrays.<br class=""></blockquote><div class=""><br class=""></div><div class="">Maybe that’s the point: They don’t. And it is my understanding that they shouldn’t need to; that Swift should be for everyone and a great language to get into programming.</div><br class=""><blockquote type="cite" class=""><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">This behavior described in help/documentation/tutorial for Swift, this is how Swift works with arrays.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div class=""><br class=""></div><div class="">Yes, and I agree with you that people should read the documentation.</div><div class="">However, the question is: Is this behavior optimal? Is a runtime error really the best way to handle this for the most common use case of arrays?</div></div></div></div></blockquote><div><br class=""></div><div>Yes. If you are reaching out of bounds of the array, there is a computation error (most likely) and the app is in an incosistent state and it's always better to crash than to pretend it's all OK and potentially do some harm to user's data.</div><div><br class=""></div><div>If the getter returned an optional, most people would get annoyed really quickly and started just placing ! everywhere, which would make the code the same, without the diagnostic message which index was accessed.</div><div><br class=""></div><div>There is only a handful of usecases where it is advantageous to have the behavior described and no one can stop you from creating an extension and adding an accessor method that returns an optional.</div><div><br class=""></div><div>AFAIK I don't know any language that is as strongly typed as Swift whose default behavior would be allowing to reach our of the bounds without a runtime error.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">But the definition of “most common use case” varies wildly. Hence my idea to have separate classes for separate needs.</div><div class=""><br class=""></div><div class="">In the end, what’s most important to me is to be able to have a consistent mental model. Something simple like: If I’m using classes called “unsafe” or exclamation marks, my app might experience runtime errors. That’s something the students I’ve taught could understand easily.</div><div class=""><br class=""></div><div class="">- Andreas</div></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>