From: darren kirby Date: 2006-08-09T04:31:30+09:00 Subject: Global variables considered harmful? --nextPart52506328.PINYBkrvoZ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello all, I have a Ruby script here that acts like a regular Unix program, including= =20 accepting a large number of command-line options/arguments. After processin= g=20 some are simple flags (ie: nil or 1) and some are text/numeric arguments.= =20 Not all are required, and some must be initialized with a default value. I= =20 have currently implemented them as globals, as their values are needed=20 anywhere in my script, from classes to functions to top-level flow control= =20 code... Now I know you are not supposed to rely on globals if you can help it, so I= am=20 trying to rewrite my script to do away with them. The problem is that there= =20 are so many command-line switches that simply passing them to the=20 class/function(s) that need them would be unwieldy. So what do I do? I was thinking of creating and populating a new class that= =20 would act similar to a C 'struct', but it seems to me that this is just a=20 different way to do the exact same thing as I have now, except that I would= =20 have to qualify the variable with a class instance making my script even mo= re=20 verbose than it is now...so why shouldn't we use globals again? Is it simpl= y=20 the namespace issue or are there other reasons?=20 Is one global hash better than 15 global scalars? I am not going to list my code here because it is 500+ lines but if you wan= t=20 to see it let me know and I will post it to the web, Thanks for consideration, =2Dd=20 =2D-=20 darren kirby :: Part of the problem since 1976 :: http://badcomputer.org "...the number of UNIX installations has grown to 10, with more expected..." =2D Dennis Ritchie and Ken Thompson, June 1972 --nextPart52506328.PINYBkrvoZ Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.4 (GNU/Linux) iD8DBQBE2OZxwPD5Cr/3CJgRAhAAAKCfiAggfsqQQNbjCnRQNt2AL7KffgCggRUU 3A3mGBuXoOGAM7/EoeNpSjE= =utuP -----END PGP SIGNATURE----- --nextPart52506328.PINYBkrvoZ--