[Glade-users] globals vs locals... again



James Cameron wrote:


The design you suggest does not sound modular, scaleable, or easy to
change.

Here is how I would do that ...
I use Plan A for main windows and small, unimportant, never to be
maintained programs.  I use Plan B especially for windows other than the
main window.

Advantages of Plan B

- all data is non-global, simplifying the code concepts, removing
dependencies, and allowing multiple instances of windows.

- it is easy to add more data elements specific to the window by
expanding the window structure (struct mw in the example),

- the pointer to the structure containing the data can be found by any
callback signal function called by any widget within the window,

    struct mw *mw = (struct mw *)
                    gtk_object_get_data(
                      GTK_OBJECT(gtk_widget_get_toplevel(widget)),
                      POINTER
                    );


James,

First, I agree with you on all these points. I was considering two
things with my initial offering.

1. Those of us who are inherently lazy often pick up the first blunt
instrument (or pointer, as it were) that they can fine laying around. If
there was something simple provided for us, we may evolve to use it ;>

2. I was also considering a way to allow the GUI builder to do even more
of the work for us. Did I mention that I was lazy? If some pointer based
or programatic method was provided and maintained by the builder, then
we could ignore the tedium, let the builder do our job for us, and have
more time to write more bad code.

Seriously, you point out a much more elegant solution. The downside is
that, although straight forward, it is a manual operation.

I'm off to clean up some code...





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