Re: Quick Question: How can I get the GTypeInfo from a GType?
- From: Ryan McDougall <ryan mcdougall telusplanet net>
- To: Federico Mena Quintero <federico ximian com>
- Cc: GTK+ development mailing list <gtk-devel-list gnome org>, gtk-app-devel-list gnome org
- Subject: Re: Quick Question: How can I get the GTypeInfo from a GType?
- Date: Thu, 08 Jan 2004 15:04:12 -0700
On Thu, 2004-01-08 at 13:39, Federico Mena Quintero wrote:
> On Thu, 2004-01-08 at 12:33, Ryan McDougall wrote:
>
> > As I read through the source codes lots of good and bad ideas pop into
> > my head. Right now I am thinking about implementing an Iterator object
> > for use in a STL style container system. I think the APIs for GList,
> > GArray, GTree, etc can be simplified and enriched by using some ideas
> > from STL's design. Of course C has no easy way to fake C++'s Generic
> > programming, but there may be yet some stuff that will transfer over.
> >
> > Aside: How efficient is GValue for faking Generic Programming?
>
> This is almost certainly not what you want to do. Glib tries to make C
> programming as high-level as possible, but not any more than that.
With regards to GValue, I assumed that the implementation wasn't up to
doing something that powerful, I thought it'd be worth while to ask. I
truly am not really interested in implementing either C++ or Common Lisp
in C.
>
> Glib comes with some simple iterators. g_list_foreach() is syntactic
> sugar and really more inconvenient than
>
> GList *l;
> for (l = my_list; l; l = l->next)
> do_something_with (l->data);
>
> g_list_foreach() is only useful if you intend to g_list_remove_link()
> the node that was fed to the callback --- it implements the usual
> while() idiom that allows for this.
>
> About the only useful iterators in glib are g_hash_table_foreach() and
> g_node_traverse(). The former, because hash tables are opaque; the
> latter, because it implements different traversal methods.
>
> Arrays are so simple to manipulate by hand that you may as well do that,
> with no loss of efficiency.
While it is true there are some iterators existent in Glib, I'm
interested if the API would be simpler, and more powerful, with a touch
more genericness added (really I don't want to try to implement
something C won't do properly -- god knows how hard it is to get C to do
OOP). For example we could have something like g_container_foreach(),
g_container_sort(), g_container_max(), g_container_copy(),
g_container_random_shuffle(), etc. not unlike the STL. If the above is
doable, I don't think that is over-reaching what C or Glib can/should
do.
>
> If you really want something like list iterators that can change the
> list, look for things like EList in the "gal" package, which Evolution
> uses.
>
> In general, don't try to make C too high-level; Greenspun's tenth law of
> programming certainly applies.
In general true, but what if you can have efficient and high-level? No
sense in being too low level just because thats what C does.
>
> Federico
>
Thanks for the input, I appreciate bouncing ideas of some good hackers I
can learn from!
Cheers,
Ryan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]