Questions tagged [globals]
The globals tag has no summary.
89 questions
1
vote
4
answers
454
views
Are there any functional approaches, to have variables that feel global (no need to pass them around explicitly), yet are local to an instance?
I'm developing a library in JavaScript (TypeScript, actually) which is split into several modules. It's meant to run both on the web and in non-web environments like Node.js.
The library is meant to ...
0
votes
2
answers
395
views
Global State, How To Do IT?
im kind of a newbie so take me easy
i face a problem every time i make a project
specially Client projects, which is Global State i always struggle to do it
for example, here is the structure of one ...
6
votes
9
answers
818
views
In "disadvantages of global states", what is the relationship between "starting state is changed" and "unpredictable"?
According to Why is Global State so Evil?, I know there are already many answers about why is "global states" bad. However, I'm not raising new reasons to oppose that. Instead, the currently ...
18
votes
11
answers
6k
views
Why is global state hard to test? Doesn't setting the global state at the beginning of each test solve the problem?
According to Why is Global State so Evil?, I know one of the disadvantages of "global state" is that it makes code "harder to test". I do not disagree with this, but what I don't ...
12
votes
5
answers
4k
views
Why is "hidden dependency" (required things not in parameter list directly) a disadvantage of "global variables", but not in "preserve whole object"?
According to https://softwareengineering.stackexchange.com/a/200092, as I know, "preserve whole object" is a refactor method that passes the whole object instead of required parameters only, ...
0
votes
1
answer
610
views
Global Variables State Management
Background:
I am working in a Java environment using Spring Boot, where I often encounter scenarios where global variable state management is critical, especially within singleton services. I have ...
0
votes
3
answers
335
views
Use of environment variable or appsettings as a counter, good or bad practice [closed]
I'm wondering if it's bad practice to have a variable in a webserver which counts the amount of incoming requests and put it in an environment variable.
In C# for example you have System.Configuration....
2
votes
7
answers
517
views
Why does "a consistent, understandable interface" differentiates database from global states?
According to some answers of How are globals any different from a database? that explains how database is different from global state:
https://softwareengineering.stackexchange.com/a/319389
https://...
0
votes
3
answers
433
views
Does turn "global state" into "passing parameter" increase the whole system coupling or not?
As far as I know, coupling is about counting number of other classes in a class, so for the following program that emulates a UI program that shows "WelcomePage" at start and also pops a ...
2
votes
4
answers
946
views
Why blaming "global state", instead of my user requirements, makes program state unpredictable?
According to Why is Global State so Evil?, I know I should not allow the existence of global state, one of the reasons is so called "it makes program state unpredictable".
However, I'm not ...
26
votes
5
answers
9k
views
Should I use a global logging variable?
Over and over again we're told, "globals are bad" and with good reason. However, I'm working with a logger that needs to be accessible everywhere in the program. Why shouldn't I create a ...
1
vote
4
answers
878
views
Passing arrays as global variables instead of pointers in C
I'm required to write the Low-Level Requirements of a Software Component which shall perform signal processing over arrays of 200k elements of integers/floats which lives in the main memory of the ...
1
vote
3
answers
567
views
Why is Dependency Injection called "alternative of global state"?I think global state still exists
According to Why is Global State so Evil?, I believe we should avoid global state, so suppose I have an App that count user clicks in all pages like it:
public class GlobalState{
public int ...
12
votes
4
answers
3k
views
How to initialize the same global resources from multiple modules independently?
I encountered the following situation: I have two modules, TokenService and Wifi which are initialized from main(). The modules themselves don't know of the existence of each other and function ...
3
votes
2
answers
497
views
How to implement a counter without global state?
I have read many blogs and stack exchange posts about global state (usually) being bad practice. I'm now trying to avoid this where possible in my code, but I'm running into a case where I don't know ...