On Thursday, 8 February 2024 at 08:23:12 UTC, thinkunix wrote:

I would never write code like this.

By all means, please share with us how you would have written that just as elegantly but "correct".

It would also break if the array 'something' had more than int.max elements.

Then don't cast it to an int. First of all, why didn't you cast it to a long? Second, why doesn't the language do this correctly so I don't have to cast it at all? If I explicitly use checkedint, it does, but I don't want to write Checked!(int, ProperCompare) all over the place. (Yes, I know I can alias it.)

I'm asking, why is the default C compatibility (of all things) rather than "safety that I can override if I need to make it faster" ?

Reply via email to