Re: any policy for foo_new() return types?



Stefan Rieken <StefanRieken SoftHome net> writes: 
> I have used GNOME and GTK+ for a long time, but only in the past few
> days I really got past the "Hello, World" stage. I couldn't help
> noticing that every foo_new() method had its own policy for what kind of
> struct to return. A few examples (sorry for using GNOME examples):
> 
> - gnome_app_bar_new() returns a GtkWidget*
>   (its far, but not "oldest" ancestor)
> - gnome_mdi_new() returns a GtkObject*
>   (its "oldest", and only ancestor)
> - gnome_mdi_generic_child_new() returns a GnomeMDIGenericChild
>   (an instance of itself)
> - gtk_adjustment_new() returns a GtkObject*
>   (its "oldest", but not its only ancestor)
> 

There is a policy, and it is:

 - widgets are returned as GtkWidget*, the principle is that you are
   most likely to need them as GtkWidget* (e.g. as the second arg
   to gtk_container_add(), to show them, etc.)
 - everything else should be returned as the most-derived type

gtk_adjustment_new() and gnome_mdi_new() are broken for historical
reasons, they should return a GtkAdjustment* and GnomeMDI*.

Havoc

  




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