Re: Consensus on getter conventions?



Karl Nelson <kenelson@ece.ucdavis.edu> writes:

>
> Thus don't look to C++ kits for answers.   If fact isn't the concept
> of returning something which needs to be freed going to be a C concept
> only.  If you change the name of the function to show this convention
> then the bindings are going to end up with rather pointless name
> distinctions.  Why make that distinction for the bindings?  (and
> using multiple names is going to cause the distinction to be
> made in the bindings.)
> 

The bindings could be made aware that this is a naming convention for
the C world and ignore it.
 
> My personal preference is to have all get_* functions which return
> something be a pointer to a "static" piece of memory.  Those
> cases where deallocation is required should return by argument.
> 
>   /* this doesn't need to be freed because it was the return */
>   const gchar* gtk_widget_get_name(GtkWidget*);
> 
>   /* this one does need to be free and it is different for that reason */
>   void gtk_font_selection_dialog_get_font_name(
>         GtkFontSelectionDialog *fsd,  gchar**);
>                                       ^^^^^
>               notice it isn't const because we give it to the user.
> 
> This only creates a conflict for the functions which return multiple
> values which you don't need to free.  (don't know if it helps the 
> problem.)

It seems to inflict a fair amount of pain on the C world to make the
distinction this way. Returns through out arguments are more awkward
to deal with than ordinary return values.

I think we should continue with the previous plan, and recommend that
bindings where the distinction does not matter do an appropriate
systematic renaming of the funtion names.

Thanks for bringing up bindings issues though; that's something that
has not been brought into this discussion previously.

 - Maciej





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