Johann Pardanaud
07/14/2023, 3:15 PMUInt
type for String.length
or Collection.size
? Is this for JVM compatibility? Is it safe to assume those values will never be negative?mkrussel
07/14/2023, 3:22 PMInt
. It also predates UInt
so changing it would be a pretty breaking change.
repeat(list.size - 1 {}
would not compile anymore, one of the numbers would have to get casted. It's better than old languages where mixed type maths were allowed and you end up with the maximum UInt if size was 0.
I think it is safe to assume that it will not be negative. But a custom collection could do something very broken.Charles Flynn
07/14/2023, 3:23 PMJohann Pardanaud
07/14/2023, 3:24 PMBut a custom collection could do something very broken.I did not thought about that, you're right, it could bring some issues. 😬
Charles Flynn
07/14/2023, 3:26 PMJohann Pardanaud
07/14/2023, 3:27 PMRuckus
07/14/2023, 4:57 PMindexOf
would return. If it returns an Int
, your missing half the collection. If it returns UInt
, how do you represent not found (which is usually -1
)? Similar issue for functions like binarySeach
, which returns -index - 1
when an element isn't found so you know the insertion point. (Using wrapper values would require instances, which would be terrible when those functions are used in hot loops.)Alexey Belkov [JB]
07/17/2023, 8:11 AMWhile unsigned integers can only represent positive numbers and zero, it’s not a goal to use them where non-negative integers are required by application domain, for example, as a type of collection size or collection index value.
Johann Pardanaud
07/17/2023, 8:34 AM