Yes - I was just looking at some code of my own where I use globals and it
sounds like it's in a generally similar context: I'm build a list of all the
files on a disk and their information.  I justify the use of globals because
it is convenient and, once I've initialized the variables, they remain
static.  The major problem with globals is when they mysteriously change.

One way to mitigate the unpleasant side-effects is to keep your globals
segregated in a namespace.

If you need to save and restore the values of your globals, you might look
at one of the ways to save a variable to file:
http://www.jsoftware.com/jwiki/Scripts/File%20J%20Variables or
http://www.jsoftware.com/jwiki/Scripts/WS%20Files .
Good luck,

Devon

On Tue, Dec 29, 2009 at 11:54 PM, Alexander Mikhailov <[email protected]>wrote:

>
> > it sounds like you've re-discovered why global variables are bad practice
>
> Yes, I know that. The reason I've used them is, of course, they seemed to
> be more convenient than alternatives.
>
> I'm writing a parser generator. From the input grammar, which is a string,
> I create some tables - nonterminals, rules... Then I build some functions,
> which essentially lookups in yet other tables, calculated along the way. The
> parser driver maintains some other tables. It's certainly possible to pass
> them all around, just not very convenient.
>
> I've done some restructuring already, and don't see immediately how to
> further simplify structures - without performance penalties, which
> (prematurely) weren't hailed much by, IIRC, Knuth.
>
> > What I usually do in a situation like that is put smoutput around line
> > 5 If I can run it with the session manager open then you can display
> > contents and some info like $ etc for everything you want.
>
> Thanks for tips. I'm not sure I know what J session manager is; I'm just
> developing with J console and an *.ijs windows open.
>
> Alex
>
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to