rmartin@clear.com (Bob Martin) (01/08/91)
In article <2840@cirrusl.UUCP> dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) writes: >Now to the point of this long discourse: I don't think there is >anything wrong with global variables, if they truly contain global >data. In a C environment, a possible problem with global variables is >that they can be *too* global, being visible even to modules that don't >need them. A possible solution is to declare a variable "static" in a >file, and have all modules that need to access that variable be in the >same file. I don't program in C++, but I don't think C++ has a better >solution to this. >-- >Rahul Dhesi <dhesi%cirrusl@oliveb.ATC.olivetti.com> >UUCP: oliveb!cirrusl!dhesi eau contrair! (sp?) C++ has the ability to declare variables which are known to a set of functions (be they in the same module, or be they not). This set is known as a class and embodies all the knowledge about a certain aspect of the problem. This is like being able to say in C that functions X, Y, QQ and P should know about this global variable since they deal with similar concepts, but the rest of the functions should not. In C++ knowledge scopes like this can overlap. A variable x can be known to function A, B and C. A variable y can be known to A, B and D. But C doesn't know y and D doesn't know x!! -- +-Robert C. Martin-----+:RRR:::CCC:M:::::M:| Nobody is responsible for | | rmartin@clear.com |:R::R:C::::M:M:M:M:| my words but me. I want | | uunet!clrcom!rmartin |:RRR::C::::M::M::M:| all the credit, and all | +----------------------+:R::R::CCC:M:::::M:| the blame. So there. |