Re: Change notification



On Fri, 18 Jan 2002, Matthias Clasen wrote:

> I noticed that the behaviour of setters wrt to change notification is not
> consistent.
> Some, e.g gtk_entry_set_visibility(), always notify:
> 
> void
> gtk_entry_set_visibility (GtkEntry *entry,
>      gboolean visible)
> {
>   g_return_if_fail (GTK_IS_ENTRY (entry));
> 
>   entry->visible = visible ? TRUE : FALSE;
>   g_object_notify (G_OBJECT (entry), "visibility");
>   gtk_entry_recompute (entry);
> }
> 
> Others, e.g. gtk_entry_set_activates_default(), notify only if the property
> actually changed:
> 
> void
> gtk_entry_set_activates_default (GtkEntry *entry,
>                                  gboolean  setting)
> {
>   g_return_if_fail (GTK_IS_ENTRY (entry));
>   setting = setting != FALSE;
> 
>   if (setting != entry->activates_default)
>     {
>       entry->activates_default = setting;
>       g_object_notify (G_OBJECT (entry), "activates_default");
>     }
> }
> 
> 
> What is the policy here ? IMO, the second is more correct.
> Would a patch to change setters in this direction be accepted ?

the second is more correct in terms of being more efficient, but
the first version isn't wrong. in general, it's better to always
supply change notification in accessors even if the value didn't
actually change, than to forget about notification.

while i'd accept a patch that adds checks for value changes around
g_object_notify() calls, i'd rather see your energy spend on making
sure that all accessors we currently have that forget about change
notification be fixed. (simply because that's a much sever issue
which needs fixing)

> 
> Matthias
> 

---
ciaoTJ




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