djones@megatest.UUCP (Dave Jones) (12/15/88)
From article <9174@smoke.BRL.MIL>, by gwyn@smoke.BRL.MIL (Doug Gwyn ): ... [ Details of an experience in program modification... ] > There are a couple of lessons that could be learned from the > experience. [The value of liberal "assert"s is one of them.] > The apparent moral is to not use block-scope static > initialization, but I think a better one would be, to design > utility programs with the thought that they should be > serially reusable. That way if they ever become subroutines > (or repeating slaves like the one I had) you already have > them in shape for the task. After having had many such experiences as Doug describes, I go even one step further. I design utility programs with the thought that they should potentially be, not just serially reusable, but reentrant! Usually I define the "global" data as one data-structure, which is initialized by a routine which takes a structure pointer as a parameter. But even if I declare actual global variables, I have this "object-orientation" possibility in mind. Fer example. For years I have been struggling with a compiler which was written to run on only one program, and then quit. It is now being used, however, as a command interpreter, which parses a program to "learn" about global declarations, etc., then is repeatedly invoked to compile commands interactively. Making the conversion to serial reuse was very tedious, and not complete. (It has to be restarted after an error.) So my team is now rewriting it from scratch. I set the globals up so that they all begin with the prefix "MPC_". There are no other occurrences of the string "MPC_". If ever I want to "objectify" the thing, all I need do is globally replace every occurrence of "MPC_" with "obj->", and add a "compiler-object" parameter named "obj" to every procedure, and voila! I can even imagine a reason for doing so. If there are two or more contexts within which one wants to compile interactive code, a compiler-object for each context is just the ticket for switching between the contexts. Dave