[vox-tech] global variables in C

Peter Jay Salzman vox-tech@lists.lugod.org
Fri, 20 Sep 2002 11:34:38 -0700


begin Bill Kendrick <nbs@sonic.net> 
> On Fri, Sep 20, 2002 at 10:34:51AM -0700, Peter Jay Salzman wrote:
> > 
> > 1. name clashing
> > 2. readability
> 
> These are good reasons.
 
i agree, but if this is all there is, i don't think the topic deserves
the amount of ire that i've seen it draw.

> I'm pretty bad about using globals all over the place, though.
> 
> My main reason, however, _is_ for readability.
> 
> In _most_ cases, the functions I'm calling need to do things to,
> or refer to, the same variables over and over again.
> 
> As an example, in my games I open the SDL window surface and name it
> "screen".

(good stuff snipped)
 
yeah, you're SDL is pretty much the same with my experiences with gtk+.

in gtk:

   most of the functions have absurdly long names to begin with.  i know
      you've seen xlib functions.  imagine them with the prefix "gtk_".

   there are so many objects that you end up having to call them long
      names just to keep it straight, like "upper_left_radio_button"

   whenever you pass upper_left_radio_button, you almost always need to
      typecast it to help C with typechecking.  so you almost never pass
      upper_left_radio_button, you actually pass something like
      GTK_OBJECT(upper_left_radio_button).  35 characters for a stupid
      radio button!   :-)

i can go on, but gtk programming gets very ugly very quickly.  passing
data to callbacks is a headache.  globals are actually very convenient
and enhance readability by an order of magnitude (as i physicst, i take
an order of magnitude very seriously ;)).


so yeah, my gtk (and ncurses) experiences are very similar to your
experience with SDL.

but some people are really insistent on this point, and i'm kind of
wondering why.

pete