Re: any policy for foo_new() return types?
- From: Owen Taylor <otaylor redhat com>
- To: Mark Leisher <mleisher crl nmsu edu>
- Cc: Stefan Rieken <StefanRieken softhome net>, gtk-list gnome org
- Subject: Re: any policy for foo_new() return types?
- Date: 22 Nov 2000 11:33:24 -0500
Mark Leisher <mleisher crl nmsu edu> writes:
> Stefan> I believe that it's common policy to return a GtkWidget* if this
> Stefan> is available in the ancestry, and otherwise fall back to a
> Stefan> GtkObject -- but why this policy, anyway? And why do some of the
> Stefan> above examples draw away from this policy?
>
> I really like GTK (but don't use GNOME). After many years of using
> the Intrinsics, I got used to object creation calls all returning
> Widget*, and all widget-related functions taking Widget* arguments,
> leaving the functions to check for valid subclasses instead of the
> programmer doing it explicitly.
ALthough I haven't talked to Peter about the issue, so I can't
tell you the _real_ reason for it, my take on the reasons why
having functions take the most derived type useful is:
- It makes the header files clearer
- Combined with standard programmer habits, it provides some measure
of compile time safety; because if I write:
GtkWidget *box = gtk_hbox_new (FALSE, 0);
GtkWidget *entry = gtk_entry_new ();
gtk_container_add (GTK_ENTRY (entry), GTK_CONTAINER (box));
The compiler will catch it. Of course, if I write
GtkWidget *box = gtk_hbox_new (FALSE, 0);
GtkWidget *entry = gtk_entry_new ();
gtk_container_add (GTK_CONTAINER (entry), GTK_ENTRY (box));
It won't get caught until run time, but that's a harder mistake
to make.
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]