Re: Cocoa-dev Digest, Vol 8, Issue 383
Re: Cocoa-dev Digest, Vol 8, Issue 383
- Subject: Re: Cocoa-dev Digest, Vol 8, Issue 383
- From: Graham Cox <email@hidden>
- Date: Tue, 31 May 2011 01:02:09 +1000
On 31/05/2011, at 12:03 AM, julius wrote:
> has the potential to create problems if it skips one's mind
Well, so does almost anything in life. Coding's no different.
> Of course I find decision to have NSArray count return NSUInteger somewhat curious precisely because it seems to me liable to lead to subtle errors in cases where programmers might have forgotten that NSArray count returns etc. etc.
Designers can't be expected to anticipate and compensate for your bad memory. The documentation states clearly what's what. It's up to you to take that on board. "Forgetting" is not a good reason to design something differently.
> Are you saying that the Cocoa engineers decided that NSArray count return NSUInteger in order to deter people from using [ary count] as part of an equation that accesses an element of an array? Or that they did so in order to prevent people from using the length of an array in a decision making process?
> I can't imagine that to be true.
I'm not saying that at all. Doing index arithmetic with unsigned values is perfectly straightforward if you need to do it. There's no 'deterrence' in having the type unsigned, it's the correct and logical way to represent a positive index. Making it signed does not, despite what you think, make the arithmetic any easier, nor harder, nor does it lead to less coding effort. You just have to know what you're dealing with.
> You are saying that I should write
> NSInteger zIntVal = [ary count];
Nope. I'm saying you should write:
NSUInteger zIntVal = [ary count];
...and write the rest of your code correctly. I'm not actually sure what you're trying to do with it.
> I think the use of NSUInteger in this context is misguided.
So file bugs against it. Good luck with that. I doubt you'll get much support from many programmers on this list however.
> This does not mean we should not use NSUInteger simply that our use of it should be judicious and in places where it might be expected and not where it might cause difficulties.
I would say that its use as an index in NSArray is a perfect example of using it judiciously, in a place where it would be expected, and where it does not cause difficulties (for most of us anyway).
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden