CodeSOD: Static State Note

CodeSOD: Static State

A C++ code review revealed a concerning pattern involving getters and setters. The getField method, expected to be a simple getter, unexpectedly called a setGetField function. This setGetField function used a boolean flag to determine whether to set or get a value. Worse, the value was stored in a static variable within setGetField. The static variable meant that the value was shared across all instances of the class, effectively creating a singleton. The reviewer's initial reaction was disbelief, suspecting a prank. However, encountering this pattern repeatedly led to frustration and questions about the developers' competence and hiring practices. The repeated use of this flawed pattern highlighted serious concerns about the codebase's quality and the developers' understanding of basic programming principles. The issue centers around improper encapsulation and the unintended consequences of using static variables within class methods. The code's design resulted in a shared state across all instances, violating core OOP principles.