[vox-tech] global variables in C
Dave Peticolas
vox-tech@lists.lugod.org
20 Sep 2002 12:09:37 -0700
--=-1AL9n4KHmaKujZ4jezaN
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
On Fri, 2002-09-20 at 11:47, Peter Jay Salzman wrote:
> but i can certainly imagine option 5 (data coupling) being detrimental
> to code maintenance. when you look at a screen and see a thick dense
> blob of code everywhere. kind of like how perl can get. as in, you're
> normally black xterm background looks completely white when you don't
> have your glasses on.
If your functions have too many arguments you can always
start consolidating those arguments into structures to improve
readability.
> to be honest with you, i asked this question because someone challanged
> me to argue the point of "globals are bad". other than the 2 reasons i
> gave above and the fact that it's conventional wisdom, i really can't
> come up with much. i was hoping to get some ideas.
I think the argument about coupling is a good one. Functions that
don't change global state are 'isolated' in this sense -- the changes=20
the function can make to the program state are restricted by the caller
to the arguments being passed in, whereas in a program with global
variables, the potential changes are much broader in scope, and
therefore harder to think about when you are writing new code.
I agree with you about the wordiness of gtk+. A lot of that is due
to trying to be OO in C. Unless you are writing lots of custom widgets,
you really ought to check out using gtk+ through one of the many=20
scripting languages that wrap gtk+ and combining that with the
Glade UI building tool. I have found the combination of Glade/Scheme
to be a breeze. And since scheme has real closures, no need for
funky 'user data' pointers in callbacks!
dave
--=-1AL9n4KHmaKujZ4jezaN
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQA9i3Jx5effKKCmfpIRAobWAJ9NBRvpiHcZ8a+qwccxdErpBfrSSwCgouFf
mkLT0MVLZ3C/eke8Dj7EwUk=
=rKYR
-----END PGP SIGNATURE-----
--=-1AL9n4KHmaKujZ4jezaN--