<div dir="ltr">On Thu, Jun 23, 2016 at 5:12 AM, Andreas Ley via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">(First time using a mailing list; I hope this message ends up in the correct thread)<br>
<br>
This is a topic that comes up regularly on the Swift evolution mailing list and off it.<br>
After reading through all the respective threads again, there seem to be the following two camps:<br>
<br>
Arguments made for crashing when accessing a non-existent index:<br>
- fast<br>
- shows bugs quickly<br>
<br>
Arguments made in favor of returning an optional by default:<br>
- safe (as in "doesn't crash")<br>
- similar to what other modern languages do<br>
- what an unexperienced Swift developer would expect<br>
<br>
All are valid arguments, but for different use cases.<br>
In my opinion, the biggest problem is that there's no indication that subscripting can crash on the default array. Alternative subscripts for bounded access wouldn't solve this either.<br>
<br>
Maybe Swift should have two different array classes: A fast, fast-failing "UnsafeArray" and a default safe "Array". This would prevent unexpected crashes for new Swift programmers while still providing a faster alternative for those who do low-level stuff. The name "UnsafeArray" would clearly communicate that this class should be handled with care.<br></blockquote><div><br></div><div>I can see where you're coming from, but IMO the ship has sailed to change the performance characteristics of every array currently written in Swift. Moreover, as Dave A. has pointed out before, crashing isn't "unsafe" in the sense it's used in Swift. It's actually quite safe, in that you're immediately prevented from doing anything nonsensical based on your incorrect assumption. If I saw a type called UnsafeArray, I'd imagine that it'd allow me to peek beyond the end of my array without crashing.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
- Andreas<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div><br></div></div>