Global Variables: Not the Devil You Think They Are

2025-02-03

This article uses a simple counter example to demonstrate how avoiding global variables can unexpectedly lead to bugs. The author argues that the problem isn't global variables themselves, but the hidden nature of data access – "action at a distance". Different variable types are analyzed, and the article explores ways to use global variables appropriately in specific scenarios, such as encapsulating them into functions or using types that only allow append operations, thus preventing issues caused by "action at a distance".