Login | Register
My pages Projects Community openCollabNet

Discussions > dev > RE: [gef-dev] Performance suggestion 1 - Arrays

gef
Discussion topic

Back to topic list

RE: [gef-dev] Performance suggestion 1 - Arrays

Reply

Author hallvard
Full name Hallvard Trætteberg
Date 2004-01-11 12:24:15 PST
Message Bob,

Iterators was one of the reasons I was thinking about move away from
Collections.
 

Iterators are only bad when they're the only way to iterate. Usually you
can also iterate by asking for the size and using indexed access, i.e.
getChildCount() and getChild(int). Adding getChildIterator will make
some kinds of iterations easier, since the iterator can be passed to and
returned from methods (the main advantage of encapsulating state in an
object).

I thought about being more specific on the type of collection and
returning Lists instead of Collections. It then seemed to me only one
step further to go completely to arrays instead as the advantages are
well known. Efficiency and type safety.
 

Type safety should be enforced by the API, not necessarily by the
underlying storage mechanism. You are not thinking of returning the
array itself from any methods are you? Similarly, you can use a List
underneath, while not allowing direct access to it, instead use
getChildCount and getChild (you'll also want getChildPosition() etc.).

Also the problem with iterators is that you cannot find the size. I
think better to return a collection or an List and the client coder has
the option of how to iterate.

If you must return a list, you must ensure that it is not modified
incorrectly.
 
Hallvard
Attachments

« Previous message in topic | 4 of 7 | Next message in topic »

Messages

Show all messages in topic

[gef-dev] Performance suggestion 1 - Arrays Bob Tarling <bob dot tarling at ntlworld dot com> Bob Tarling <bob dot tarling at ntlworld dot com> 2004-01-11 11:08:30 PST
     RE: [gef-dev] Performance suggestion 1 - Arrays hallvard Hallvard Trætteberg 2004-01-11 11:26:50 PST
         Re: [gef-dev] Performance suggestion 1 - Arrays Bob Tarling <bob dot tarling at ntlworld dot com> Bob Tarling <bob dot tarling at ntlworld dot com> 2004-01-11 11:44:38 PST
             RE: [gef-dev] Performance suggestion 1 - Arrays hallvard Hallvard Trætteberg 2004-01-11 12:24:15 PST
                 Re: [gef-dev] Performance suggestion 1 - Arrays Bob Tarling <bob dot tarling at ntlworld dot com> Bob Tarling <bob dot tarling at ntlworld dot com> 2004-01-11 15:30:26 PST
                     RE: [gef-dev] Performance suggestion 1 - Arrays ipreuss Ilja Preuß 2004-01-14 04:59:23 PST
                         Re: RE: [gef-dev] Performance suggestion 1 - Arrays bob dot tarling at ntlworld dot com bob dot tarling at ntlworld dot com 2004-01-14 05:33:35 PST
Messages per page: