On Thu, Jul 24, 2008 at 4:15 PM, Steve Cronin <[EMAIL PROTECTED]> wrote:
> I have a mutable array, M.  I want to remove an object, O, from M; O might
> not be in M.
> M which is being constantly diminished could become empty.
>
> Is this code worth it?
> if ([M count]>0) [M removeObject:O];
>
> OR should I just do
> [M remove O];
>

I'm not quite sure what you gain in the first case? If the array is
already empty, then what extra processing do you imagine will be in
-removeObject: that you will save by checking -count first.

You may be making assumptions about how the mutable array works
internally (I'm assuming you mean an NSMutableArray), which is a bad
thing to do for any class and in the case of Apple's collection
classes, the internals can change on you:
<http://ridiculousfish.com/blog/archives/2005/12/23/array/>

I think that your first piece of code is far less readable than the
second, because I don't find it obvious why you're checking -count
first?

And as mentioned, measuring performance is the only way to get a true
answer as to which method is better.

Phil
_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to