Re: Re: NSEnumerator -> NSPopupButton (was: Re: NSPipe / NSTask ls -> Array)
Re: Re: NSEnumerator -> NSPopupButton (was: Re: NSPipe / NSTask ls -> Array)
- Subject: Re: Re: NSEnumerator -> NSPopupButton (was: Re: NSPipe / NSTask ls -> Array)
- From: "Michael Ash" <email@hidden>
- Date: Sun, 16 Jul 2006 15:48:29 -0400
On 7/16/06, Prachi Gauriar <email@hidden> wrote:
Also, using an enumerator with an array is actually less efficient
(and harder to understand, IMO) than just using a for loop like:
unsigned ttyCount = [ttysArray count];
for (unsigned i = 0; i < ttyCount; i++) {
[ttyPopUpButton addItemWithTitle:[ttysArray objectAtIndex:i]];
}
First, efficiency doesn't really matter most of the time. Write what's
easiest to understand, then optimize where it's important, and always
optimize later.
Second, this is not the case in my tests on large arrays. The for loop
approach was 10-20% slower than NSEnumerator. Details are here:
http://www.cocoadev.com/index.pl?NSEnumeratorSpeed
Whether it's easier to understand is basically personal taste. I think
enumerators are nicer (in particular, they can let you switch data
structures without changing code), but I've seen a lot of really
terrible newbieisms related to keeping track of a location in an array
by using a stored NSEnumerator instead of a simple index. In any case,
knowing the alternatives is a good thing.
Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden