Eric said:
Bartc, I *love* your program! It's the perfect adjunct
for my super-duper workspace/gamespace/faceplace app, and the
combination will be so enormously popular that we two will
become Filthy Stinkin' Rich. My plan is to set my program up
as a framework that runs a couple dozen copies of your code,
all as part of one giant program. Is there anything about
your program that might cause us trouble?
I guess it might need tweaking. But I'd imagine a lot of softwares would
give the same trouble, globals or not.
Okay, that's whimsical -- but I lived through the aftermath
of just such a migration at a PPOE. The program was a document
editor that integrated text, drawings, pictures, charts, tables,
and so on all in one package (run-of-the-mill stuff nowadays,
but this was a couple decades ago). You launched the program,
it opened your document, you fiddled with it, and then you shut
the program down.
Well, that program of mine was some years ago, and I've improved since (I
hope) but still use plenty of globals and file-scope variables where
appropriate.
Looking at that code now, I could probably reduce the globals by half. But
there would still be a good case for leaving the rest in.
The application was a CAD-type product with a built-in language (compiler
and interpreter) for running much of itself and for add-ons. So it was quite
extensive, and it's difficult to imagine how I could eliminate most
globals -- working from it's original code.
Starting anew however things would be different (a C interpreter core
running most of the code as a dynamic language, and with this setup, sharing
problems become simpler).
But take this one example of a global variable (the code was not C):
byte winnt /* set to 1 when this is WinNT, 0 otherwise */
What was I supposed to do with that? A few functions out of thousands need
to know that value.
Then we decided to embed our document editor into a full-
fledged document management system, so you'd work on several
documents at the same time in different windows. Unfortunately,
the editor was festooned and beribboned with global variables
pertaining to "the" document being edited. Thousands of them,
just like your program ...
No, my program could in theory have coped with multiple documents
(drawings), although the user could only edit one. That's why I only had
2000 or so globals..