I've been wondering for a while now if there is any reason why
- accessing an element in an array (Sequence) is done by an Int instead of an UInt
- count returns an Int instead of an UInt
I haven't come to a answer myself, but I considered the following:
- You don't want to cast between UInt and Int all the time, even though I think this won't be an issue because people would use UInts probably more often
- Someone implementing the protocol could have a collection with negative indexes and negative count. Is there any example for this?
- Because of objective-c interoperability
- Because people are used to it from other languages
Advantages UInts could bring:
- More "safety" since negative values can't be used to access elements
- It would be more natural because people don't expect the count or index to be negative
However, I feel like I missed something. I know this will not change anyway. I just want to know if there is any "important" reason for this.
Someone had a reason for this at any point of swift development. So I felt like this is a good place to ask.