DO I NEED TO BE GLOBAL?
This is the first question you should always ask if this GLOBALY variable is used, for example. in all contexts. The answer is almost certain ... no, it is not .
Consider the context
Is the variable a global state, or is it a context? The global state is usually rare, context, on the other hand, is quite common. If this global state considers wrapping in singleton mode, you can control how to interact with your global ones. Using Atomic<> is probably not a bad idea, you should at least consider synchronization.
If this is a context, then it must be explicitly passed in the structure or class, since the data is clearly not related to this context. A missing context may seem like a burden, but it shows very clearly where the context comes from, and not just refers to random variables from the air.
What is scope?
It may seem strange to say that global areas are covered by scope, but any global declaration declared in a single file can be declared static and thus cannot be deleted from any other file. This means that you can restrict access to global status in this area. This prevents accidental changes to variables.
Mgetz
source share