Re: Consensus on getter conventions?



On 24 Aug 2000, Maciej Stachowiak wrote:

> Derek Simkowiak <dereks@kd-dev.com> writes:
> 
> > -> 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.
> > 
> > 	I like Karl's idea.  Makes it clear as day.
> > 
> 
> Karl's idea makes getters that return references pretty
> inconvenient to use from C; you must use a temporary variable even if
> you're going to pass the result to a function that will assume
> ownership.

urm, seing temporary arguments used in an argument of yours really made my day.
we have close to 0 functions that assume ownership, especially for strings,
and the main reason for me to keep _get_ as a the static return variant,
and recommend that for general use over duplicating variants was coding
convenience for nested function calls. that is aboid temporary variables
for the common case. with getters generally duplicating, and people probably
choosing _get_ over _peek_ simply because it's established API (beyond
the gtk/gnome/C lands even), we'll introduce legions of temporary variables
anyways, so you may just as well pass them in by location, it doesn't
make much of a difference at that point anymore.

> 
>  - Maciej
> 

---
ciaoTJ






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