Globals

One of the great double-edged swords of programming.

Advantages

On the plus side, having a global that's accessible from anywhere slightly simplifies coding when you only have one of something — it means there's no need to pass it around to functions or save references to it in classes.

Disdvantages

On the minus side, having a global that's accessible from anywhere complicates debugging — without looking at the implementation of any given function, you have no idea if it's going to modify that global or not. It also complicates Refactoring, as there's less incentive to consider whether a given piece of code really should be using any given dependency or not itself.

Alternatives

Dependency Injection

Examples

Globals in C++