| View previous topic :: View next topic |
| Author |
Message |
Peter Morris [Droopy Eyes Guest
|
Posted: Mon Jan 05, 2004 9:25 pm Post subject: Iterator vs For loop |
|
|
Hi all
Is there any advantage to an iterator over a for loop where
a) The list is already exposed by its owner
b) The list is not a composite list
Pete
|
|
| Back to top |
|
 |
Joanna Carter (TeamB) Guest
|
Posted: Mon Jan 05, 2004 10:00 pm Post subject: Re: Iterator vs For loop |
|
|
Peter Morris [Droopy Eyes Software] wrote:
| Quote: | Is there any advantage to an iterator over a for loop where
a) The list is already exposed by its owner
b) The list is not a composite list
|
If the list already has an indexed Item[] property then an Iterator could be
seen as superfluous.
However, Iterators have their benefits in constructing tools like skip
iterators that filter a list, or tree iterators where the Tree has no
concept of indexing.
Iterators are best obtained from the list that they will iterate i.e. the
list should have a GetIterator method.
Could you explain a & b, they do not mean much to me at the moment?
Joanna
--
Joanna Carter (TeamB)
Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
|
|
| Back to top |
|
 |
Marc Rohloff Guest
|
Posted: Mon Jan 05, 2004 10:02 pm Post subject: Re: Iterator vs For loop |
|
|
Peter Morris [Droopy Eyes Software] wrote on Mon, 5 Jan 2004 21:25:57 -
0000 ...
| Quote: | Is there any advantage to an iterator over a for loop where
a) The list is already exposed by its owner
b) The list is not a composite list
|
For loops are generally considerably faster than for loops, however an
iterator can offer a good level of abstraction even in a simple case
like this. For example you may later want to make your list a composite.
Well designed iterators can also insulate your code from the impact of
changes (additions and deletions) to the list while you are busy
iterating over it.
Marc Rohloff
marc rohloff at bigfoot dot com
|
|
| Back to top |
|
 |
Joanna Carter (TeamB) Guest
|
Posted: Mon Jan 05, 2004 10:03 pm Post subject: Re: Iterator vs For loop |
|
|
Marc Rohloff wrote:
| Quote: | For loops are generally considerably faster than for loops
|
But which for loop is faster? :-)
| Quote: | Well designed iterators can also insulate your code from
the impact of changes (additions and deletions) to the list while you
are busy iterating over it.
|
Good point, I have the Iterator observe the list and when a deletion occurs,
I can shortcut terminate the Iterator.
Joanna
--
Joanna Carter (TeamB)
Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
|
|
| Back to top |
|
 |
Carl Caulkett Guest
|
Posted: Mon Jan 05, 2004 10:40 pm Post subject: Re: Iterator vs For loop |
|
|
Joanna Carter (TeamB) wrote:
| Quote: | Marc Rohloff wrote:
For loops are generally considerably faster than for loops
But which for loop is faster?
|
The first one obviously.
Like, duh!
<g>
--
Carl
|
|
| Back to top |
|
 |
Ritchie Guest
|
Posted: Mon Jan 05, 2004 11:47 pm Post subject: Re: Iterator vs For loop |
|
|
In article <3ff9e026$1 (AT) newsgroups (DOT) borland.com>, [email]joannac (AT) btinternetXX (DOT) com[/email]
says...
| Quote: | Marc Rohloff wrote:
| For loops are generally considerably faster than for loops
But which for loop is faster?
|
LOL - voops :)
| Quote: | Good point, I have the Iterator observe the list and when a deletion occurs,
I can shortcut terminate the Iterator.
|
My own variant does a nil-and-pack type of operation where deleted items
are nil-ed (and packed when all iterators go away), and every created
iterator gets the Count of the list when it's created, so it never goes
past it even if items are added later. Simplistic way to keep a
relatively consistent view of the list, but it works well :)
Happy New Year, Joanna :)
-- Ritchie Annand
Senior Software Architect
http://www.malibugroup.com
http://nimble.nimblebrain.net
http://wiki.nimblebrain.net
|
|
| Back to top |
|
 |
Joanna Carter (TeamB) Guest
|
Posted: Mon Jan 05, 2004 11:50 pm Post subject: Re: Iterator vs For loop |
|
|
Ritchie wrote:
| Quote: | Happy New Year, Joanna
|
Ta muchly and ditto to you :-)
Joanna
--
Joanna Carter (TeamB)
Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
|
|
| Back to top |
|
 |
Bryan Crotaz Guest
|
Posted: Tue Jan 06, 2004 3:37 am Post subject: Re: Iterator vs For loop |
|
|
| Quote: | For loops are generally considerably faster than for loops, however an
iterator can offer a good level of abstraction even in a simple case
like this. For example you may later want to make your list a composite.
Well designed iterators can also insulate your code from the impact of
changes (additions and deletions) to the list while you are busy
iterating over it.
|
ESPECIALLY when multithreading! Don't always want to lock the list to
iterate it!
Bryan
|
|
| Back to top |
|
 |
Marc Rohloff Guest
|
Posted: Tue Jan 06, 2004 1:34 pm Post subject: Re: Iterator vs For loop |
|
|
Joanna Carter (TeamB) wrote on Mon, 5 Jan 2004 22:03:30 -0000 ...
| Quote: | Marc Rohloff wrote:
| For loops are generally considerably faster than for loops
But which for loop is faster?
|
You guys are a tough audience! But you all understood that what I meant
to say was: For loops are generally considerably faster than iterators.
Right?
Marc Rohloff
marc rohloff at bigfoot dot com
|
|
| Back to top |
|
 |
Peter Morris [Droopy Eyes Guest
|
Posted: Tue Jan 06, 2004 1:45 pm Post subject: Re: Iterator vs For loop |
|
|
Don't worry Rold, I understood ;-)
| Quote: | You guys are a tough audience! But you all understood that what I meant
to say was: For loops are generally considerably faster than iterators.
Right?
|
|
|
| Back to top |
|
 |
Rudy Velthuis (TeamB) Guest
|
Posted: Sun Jan 11, 2004 11:05 am Post subject: Re: Iterator vs For loop |
|
|
Marc Rohloff wrote:
| Quote: | For loops are generally considerably faster than for loops
|
Er...
--
Rudy Velthuis (TeamB)
"Hemingway was a jerk."
- Harold Robbins
|
|
| Back to top |
|
 |
|