3 ms·
> Another example are "near constants" like a locale setting, an environment variable that gets detected once at startup, or a development feature flag. The "pr
by clarry 7y ago
> Another example are "near constants" like a locale setting, an environment variable that gets detected once at startup, or a development feature flag. The "proper" way to structure those is to create a settings object and pass it to every function that needs them, but judicious use of a well-documented global can prevent a lot of boiler plate code.
In small programs, globals are ok, but in larger programs a better approach would be a global accessor that gives you read-only access:
printf("%s\n", Environment()->Host);
This doesn't require passing an object to every function, and the application still can't trample on these variables.