RE: The iterator interface



Hi Philip, 

>-----Original Message-----
>From: tinymail-devel-list-bounces gnome org 
>[mailto:tinymail-devel-list-bounces gnome org] On Behalf Of 
>ext Philip Van Hoof
>Sent: Monday, August 07, 2006 20:43
>To: Binnema Dirk-Jan (Nokia-M/Helsinki)
>Cc: tinymail-devel-list gnome org
>Subject: RE: The iterator interface
>
>On Mon, 2006-08-07 at 13:29 +0300, Dirk-Jan Binnema nokia com wrote:
>>  
>> Hmmm.... I was thinking about programmer friendliness; if I always 
>> have to unref the reference, I always have to assign the retval to a 
>> variable, and do the unref.
>> 
>> However, maybe I'd like to do something like:
>> 
>> while (!tny_iterator_iface_is_done (iter)) {
>> 	do_something_nifty (tny_iterator_iface_current(iter, FALSE));
>> 	tny_iterator_iface_next (iter);
>> }
>
>while (!tny_iterator_iface_is_done (iter)) {
>	GObject *a;
>	do_something_nifty (a = tny_iterator_iface_current(iter));
>	g_object_unref (a);
>	tny_iterator_iface_next (iter);
>}

That proves my point, I guess; a very common operation takes 50% more
code;
with the additional risk that people forget the unref....


>> Of course, nothing really special, but it would make for a 
>little bit 
>> nicer client code. Alternatively, instead of the boolean, we could 
>> have tny_iterator_iface_current_floating.
>
>Naaah. To much API in my opinion. Let's be consistent.

>Now, who's going to write the patch? :). I can't. Mickey Mouse 
>doesn't allow me. 

You mean the patch to make most iterators ops void, and the unref
thingy? I can do that. Will be tonight though.

There's one class of errors where the compiler
might help, ie. the __attribute__((warn_unused_result)), and there's
a macro for that in glib, G_GNUC_WARN_UNUSED_RESULT. Any problem
with using that one?

Best wishes,
Dirk.



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