Global variables and other singletons are bad, for obvious reasons: when there are hundreds of them in different parts of the program, they are difficult to track and very easy to break, using incorrectly.
Problem one: imagine, you are a new person in the project, you want to find some parameter whose purpose you understand and its existence is obvious, but the exact name is unknown. Let me remind you, hundreds of them throughout the project. How will you do it? Not to mention that similar logical objects will probably have variables with similar names. To solve this problem, they are clustered into namespaces and made static class fields. Similar to the way files are grouped into folders.
Problem two: there is a temptation to change data (variables) directly, bypassing the complexity of business logic. It is very easy to break the logical integrity of the data, but this error can emerge over time in a random place and its source will be VERY problematic. To solve this problem, the main property of the OOP paradigm is encapsulation. Class variables should be private, set / get methods are exposed.
And indirect problem number 3: global variables “nails” parts of the program among themselves so that it is impossible to independently test its individual parts, since will have to play very much large pieces of the environment. After that, any change in business logic is threatened by a “butterfly effect,” which may echo where you were unaware. To solve this problem, an abstraction is created from dependent data (in the form of interfaces or abstract classes), which is introduced from the outside and can easily be replaced by a test "dummy" (Mock object).
ZY Compared to these problems, having to write the name of a class to access a variable is nonsense.
thread_countdoes not make sense as a global variable, it can be updated by anyone, anytime, or it may not. If you make it a private static variable of some base class for your threads (or a private variable of the thread manager), then a class will appear responsible for its relevance. A responsibility! That's what matters. - vp_arth