On 30-May-2011, at 11:05 PM, julius wrote:

> 
> On 30 May 2011, at 15:52,  Roland King <r...@rols.org> wrote
>> 
>> On 30-May-2011, at 9:18 PM, julius wrote:
>> 
>>> 
>>>> They used the datatype which maps onto the thing they are describing, 
>>>> array elements are non-negative integers, so they used NSUInteger. 
>>> So are you saying that the designers made this decision solely because of a 
>>> particular interpretation of dogma?
>> 
>> No. I am saying that semantically the 'size' of an array is a non-negative 
>> integer and thus the correct way to represent it is with a data type which 
>> represents non-negative integers. 
> 
> If that were all there was to it then I might agree but I don't think it is.
> I think issues of program language complexity and the propensity of language 
> constructs to induce coding errors are more important.
> 
> Julius
> 

Whist seeing your side, I respectfully disagree. I think data types should as 
closely as possible align with the data they actually represent. Perhaps the 
best solution would be an object data type for size of an array which had 
syntax which stopped anyone misusing it, methods for iteration, for comparison 
etc. which left no way to make an error (I think that's called C++ :) ). I'm 
personally very happy with unsigned integer for size of/index into array and 
when I see 'unsigned' on a type I'm reminded what comparisons are valid on the 
zero side; I will admit to having blown myself up on more than one occasion 
overflowing a type on the high side, I've rarely messed up subtracting unsigned 
types without considering whether the subtraction is valid, but I'm sure there 
was a time years ago I learned that lesson and probably the hard way. 

I still think that if you do reasonable checks on array sizes before you use 
them, most comparisons are valid for sizes without issue and those checks 
always seem to me to be part of the logic you should be writing anyway to 
differentiate cases. I like NSUInteger because it reminds me what type of data 
I'm really dealing with. If Cocoa used NSInteger I'm sure I'd have gotten used 
to that as well, and I'm sure I'd have found a few cases in which I'd wondered 
why they didn't do it the unsigned way. 



> 
> 
> http://juliuspaintings.co.uk
> 
> 
> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to