Use the [state] tag for questions pertaining to retained information determining the behavior of a program.
Questions tagged [state]
160 questions
422
votes
17 answers
Why is Global State so Evil?
Before we start this, let me say I'm well aware of the concepts of Abstraction and Dependency Injection. I don't need my eyes opened here.
Well, most of us say, (too) many times without really understanding, "Don't use global variables", or…

Madara's Ghost
- 8,787
- 9
- 25
- 33
264
votes
22 answers
How are globals any different from a database?
I just ran across this old question asking what's so evil about global state, and the top-voted, accepted answer asserts that you can't trust any code that works with global variables, because some other code somewhere else might come along and…

Mason Wheeler
- 82,151
- 24
- 234
- 309
116
votes
8 answers
How to keep applications stateless
This may be a convoluted question, but I'm trying to get a better understanding of statelessness.
Based on what I've read, web applications should be stateless, meaning each request is treated as an independent transaction. As a result, Session and…
user253058
94
votes
6 answers
What's the difference between stateful and stateless?
The books and documentation on the MVC just heap on using the Stateful and Stateless terms. To be honest, i am just unable to grab the idea of it, what the books are talking about. They don't give an example to understand any of the either state,…

Pankaj Upadhyay
- 5,060
- 11
- 44
- 60
79
votes
3 answers
"state" or "status"? When should a variable name contain the word "state", and when should a variable name instead contain the word "status"?
Reading code and discussions pertaining to code, I often see the words "state" and "status" used interchangeably, but the following tendencies seem to exist:
When a variable holds a value intended to indicate that something is in a certain state,…

Will
- 901
- 1
- 6
- 7
50
votes
3 answers
Are front-end state management tools an anti-pattern?
I'm currently reading "Code Complete" by Steve McConnell. In section 13.3 "Global data" in last paragraph "Don’t pretend you’re not using global data by putting all your data into a monster object and passing it everywhere", he said:
Putting…

CoderDesu
- 1,005
- 5
- 10
43
votes
4 answers
What is State, Mutable State and Immutable State?
This is a newbie question, but I couldn't find a newbie-proof enough answer on Google.
What do people mean when they say 'state' - in programming in general, and in OO programming specifically?
Also, what is mutable and immutable state - again,…

Aviv Cohn
- 21,190
- 31
- 118
- 178
31
votes
1 answer
Is there a good formal pattern to manage state in MVVM?
I have started learning about Redux and React in the web-world, and the more I learn about it the more I'm realizing how painful state management is in the desktop-world with WPF's MVVM-style architecture (using Caliburn specifically to bind Views…

willem
- 1,053
- 9
- 10
26
votes
5 answers
Functional Programming: right ideas about concurrency and state?
FP proponents have claimed that concurrency is easy because their paradigm avoids mutable state. I don't get it.
Imagine we're creating a multiplayer dungeon crawl (a roguelike) using FP where we emphasize pure functions and immutable data…

Mario T. Lanza
- 1,700
- 1
- 13
- 22
20
votes
5 answers
Is the benefit of the IO monad pattern for handling side effects purely academic?
Sorry for yet another FP + side effects question, but I couldn't find an existing one which quite answered this for me.
My (limited) understanding of functional programming is that state/side effects should be minimised and kept separate from…

Stu Cox
- 311
- 2
- 6
18
votes
2 answers
Is it a good idea to define one big private function in a class to maintain valid state, that is, to update the object's data members?
Although in the code below a simple single item purchase in an e-commerce site is used, my general question is about updating all data members to keep an object's data in valid state at all times.
I found "consistency" and "state is evil" as…

site80443
- 199
- 7
17
votes
4 answers
When programming in Functional style, do you have a single application state that you weave through the application logic?
How do I construct a system that has all of the following:
Using pure functions with immutable objects.
Only pass into a function data that the function it needs, no more (i.e. no big application state object)
Avoid having too many arguments to…

Daisha Lynn
- 299
- 1
- 9
17
votes
11 answers
What is better IllegalStateException or silent method execution?
Let's say I have a MediaPlayer class which has play() and stop() methods. What is the best strategy to use when implementing the stop method in case when the play method has not been called before. I see two options: throw an exception because the…

x2bool
- 281
- 2
- 6
17
votes
2 answers
Side effect-free interface on top of a stateful library
In an interview with John Hughes where he talks about Erlang and Haskell, he has the following to say about using stateful libraries in Erlang:
If I want to use a stateful library, I usually build a side
effect-free interface on top of it so that…

beta
- 992
- 2
- 8
- 16
17
votes
4 answers
Definition of "state"
What is a good way to define "state", as in state variable or state machine, to a new (previously non) programmer? What are some good ways to explain why this concept is useful for writing software? Is the concept of state explicitly taught in…

hotpaw2
- 7,938
- 4
- 21
- 47