Re: iterator resolution



Tim Janik <timj@gtk.org> writes: 
> why bother at all?
> what's wrong about
> 
> struct _*Iter
> {
>   /*< private >*/
>   guint cache_count;
>   gpointer buffer;
>   [...]
> };
> 
> in the public header file?
> 

I've recently become a huge fan of totally opaque types; I find that
my code ends up much better for it, and functions to do things always
get written when necessary. For example the original TkText code was
constantly accessing index->tree and index->line and index->byte_index
and now since I'm chaning the iterators, I'm having to find all these
references and fix them. If the TkText code had used nice accessor
functions, I could have changed the iterators much more trivially.

In this case the opacity is extremely important, because half the
struct can be invalid at any given time and it would not only be
slightly dubious to access fields directly, it would be totally
unsafe. Moreover some of the types in the struct are not currently in
the public header files, and I don't want to put them there. So making
the struct public would not even be more convenient, and it would be
unsafe.
 
Also, I would like to be able to change the struct fields inside a
stable branch, and if I *know* no one is using them directly that's
much easier.

Anyway, the work is already done, I am not going to go back and make
it suck more now that I've already made it nice and opaque.

Just think: the current code is so well-encapsulated that you could
switch to skip lists or a gapped array representation without breaking
_any_ user code.

Havoc



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