Re: Programming style



Gus Koppel wrote:
Tristan Van Berkom wrote:


Every widget callback comes with a "user_data" argument,
and you can pass the desired data through that argument
(which is just as fast as using a global variable and is
just as clean as using a lookup_widget type of routine).


Right. However, if you want your signal handler to be able to access
more than one foreign widget, you need to define and instantiate (and
finally possibly cleanup) a struct to be passed to the signal handler
(instead of one widget directly).

If you have many widget signal handlers which need to access many
different sets of widgets you would end up defining a large number of
handler-specific structs. Keeping them apart between different handlers
while managing them properly appears more laborious and error-prone to
me than obtaining references to other widgets just as needed in a
well source-readable way within the handler.

In my experience; I rarely have to define structs to hold a number of
needed arguments, but I usually dont use glade_xml_signal_autoconnect
either (usually that code is glade_xml_get_widget/g_signal_connect
for me); to a certain extent; this is a matter of architectural
preference.

I just wanted to point out that the user data argument is usable and
efficient (since nobody had mentioned that yet).

Ofcourse there are cases where it isn't convenient to use the user_data;
I might as well also note that, with the cost of a slight overhead;
g_object_set_data (); is often usefull for this type of inconvenience.

Cheers,
                          -Tristan




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