Re: [swift-evolution] Arrays Returning Optionals instead of Index Out of Bounds

2016-06-23 Thread Andreas Ley via swift-evolution
> "..*most* people don’t expect.." could you prove this please?

I should have written “most people I know” or “the people I work with".

> Especially if they know a little of C language or other language that don't 
> allow to use wrong indexes for arrays.

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.

> This behavior described in help/documentation/tutorial for Swift, this is how 
> Swift works with arrays.

Yes, and I agree with you that people should read the documentation.
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?
But the definition of “most common use case” varies wildly. Hence my idea to 
have separate classes for separate needs.

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.

- Andreas___
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


Re: [swift-evolution] Arrays Returning Optionals instead of Index Out of Bounds

2016-06-23 Thread Andreas Ley via swift-evolution
> Please find the related proposal which was formed after the long discussion 
> in the list:
> 
> https://github.com/luish/swift-evolution/blob/proposal-lenient-collection-subscripts/proposals/-more-lenient-collections-subscripts.md
>  
> 

Thanks; I have seen this and other proposals, but none of them address the 
problem that most people don’t expect a crash when using subscripting – except 
for Erica’s excellent suggestion to make subscript throw, which would also 
require considerable changes to existing code.

- Andreas___
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


Re: [swift-evolution] Arrays Returning Optionals instead of Index Out of Bounds

2016-06-23 Thread Andreas Ley via swift-evolution
(First time using a mailing list; I hope this message ends up in the correct 
thread)

This is a topic that comes up regularly on the Swift evolution mailing list and 
off it.
After reading through all the respective threads again, there seem to be the 
following two camps:

Arguments made for crashing when accessing a non-existent index: 
- fast
- shows bugs quickly 

Arguments made in favor of returning an optional by default: 
- safe (as in "doesn't crash")
- similar to what other modern languages do
- what an unexperienced Swift developer would expect

All are valid arguments, but for different use cases. 
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.

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.

- Andreas
___
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution