RE: TnyAccountTreeModel is now a TnyListIface



On Fri, 2006-07-07 at 11:32 +0300, Dirk-Jan Binnema nokia com wrote:

> Well, 'is_last' is actually in the list, while the end element is
> not. It's conceptually 'to the right' of the last element, and 
> could be implemented by just putting a dummy element there;
> 
> Then: is_end simply means cursor->next == NULL
> 
> The iterator and list impl of course then need to be aware that
> there is one dummy element.

> Alternatively, there could be a simple boolean property in the iterator,
> which tells if it's 'valid' or something like that, then I could
> simply write my loops like
> 
> iter = tny_list_iface_create_iterator ( list );
> while (tny_iterator_iface_is_valid (iter)) {	
> 	/* do something */
> 	tny_iterator_iface_next (iter);
> }

But, is_valid and is_last would be fine for me. You just need to impl-
ement it for each current implementation.

> now, compare that with the current way you need to write a loop:

Oh but I'm not very satisfied with it myself. You don't have to convince
me there. It's just that at this moment, it works for me. But I
certainly agree there's more work todo on the iterator interface and
implementations.

I just did a very bad one so that you guys would be forced to contribute
a better one! ;). Smart huh.

> >So I'm optimistic about the speed YOU will get out if it, Dirk-Jan :D
> 
> I will look into this...  hopefully this weekend. But my iterators
> would look a bit different; so I guess we should agree about that.

Of course. Propose an API, lets discuss it and then go for it. Once I'm
receiving the patches, you know I'll probably start helping you. :)

> There also a lot of operation which (like n_th), which belong in 
> the list iface, not the iterator. A (bidirectional, random access)
> iterator has to provide only.

You are probably right.


> Also, do we really need to do locking? When will the same iterator
> be used in different threads? And would it then not be better to
> do the locking *there*, if we really need it?

We definitely need locking, yes. 

> In general, the new iterator-based API forces me to rewrite my
> code into something that is a lot uglier. The GSList's were just
> fine. (The "nice" thing about C is that without any changes, my
> code still compiles without warnings. It just crashes...)

Long live the type-safe typedef of D ;-).

> Now, I like iterators, but let's do it the right way then; I think
> the link you used (the first one for google "iterator pattern"!)
> is actually quite bad; but at least there they have the "IsDone"
> function -- that would make life a lot easier (it's my points-to-valid).

I think they used the GoF UML for it, no? But I need to check that
first. But you are right. These patterns are just guidelines. But I do
think we should keep the iterator and list API close to what Java
and .NET do. I don't think we should do it the C++ way, if that is
different. I'm very pro the Java and C# .NET frameworks and languages.

My opinion is that they got it right.


-- 
Philip Van Hoof, software developer at x-tend 
home: me at pvanhoof dot be 
gnome: pvanhoof at gnome dot org 
work: vanhoof at x-tend dot be 
http://www.pvanhoof.be - http://www.x-tend.be




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]