45
votes
Accepted
Are front-end state management tools an anti-pattern?
The problem with global variables is that they are difficult to reason about. Where is that global variable being modified? How would you even know?
When you pass around a context object (i.e. a ...
23
votes
Are front-end state management tools an anti-pattern?
The quote from the book is concerned more about code that looks like this:
var data = {
some: {
huge: {
deeply: {
nested: {
object: {
...
23
votes
Accepted
Is there a clean way to model methods that only make sense depending on the current state of the object?
What you've done here has a name. This is an internal Domain Specific Language (iDSL). It can be used like this:
void execute(PlannedMission plannedMission) {
plannedMission
.start()
...
18
votes
Accepted
Stateful vs non-stateful app
In the context of web applications, we call the server stateful if it maintains transient state in memory, rather than storing any data externally (e.g. in a database).
Stateful applications have a ...
15
votes
Is the global state believed to be evil because of its nature or mostly due to its usual, no-rules usage?
Is this what the global state must overcome to be accepted?
No. Adding contracts to what goes into and out of global state is as easy as using a language with real types. There are lots of those and ...
11
votes
Is global state really always bad?
I think you are conflating two (surely related) things here: global state, and global variables which are accessible from everywhere in a huge application. An application can have global state without ...
10
votes
Accepted
Definition of static property of object in OOP
The explanations you quoted make sense from a semantical English point of view, but they are horribly ambiguous because it uses words that have very specific meaning in software development terms, but ...
8
votes
What's the proper way to think about state monads?
I'd like to offer a slightly different perspective that may help with your current problem.
Don't think of state changes as bad. After all, if there were no state changed in your program, you could ...
8
votes
Accepted
Is it better to use lambda functions or boolean variables to record state
Using these kinds of object-oriented or functional techniques can be super neat and elegant. If you need a fancy name for what you are doing here, I suggest the State Pattern, with function objects ...
8
votes
If a system talks to a database to get some previous information to serve a request, does that make the system **stateful** or **stateless**?
It depends on the context you’re talking about. Or more visually, how big the box named “system” is.
Since the DB (or cache, or external system, etc.) might change, it is stateful in that you can’t ...
7
votes
REST API: is it a violation of naming convention if a GET method changes the expiry of the a redis key?
The data being in redis is implementation detail. It matters if state of the data changes during the request, not if just anything changes. If It was like that, turning on access log would efectively ...
7
votes
Accepted
If a system talks to a database to get some previous information to serve a request, does that make the system **stateful** or **stateless**?
Words may be used for different purpose in different contexts:
For a class, the term stateless is used to describe the special case of absence of attributes and properties. A statefull class is in ...
7
votes
Accepted
Is rebooting a server idempotent or not?
The problem here is that Tim Bray doesn't explain why he thinks it's not idempotent. The concept of idempotency is somewhat subjective. When we call a PUT twice there are a number of things that ...
7
votes
Is there a clean way to model methods that only make sense depending on the current state of the object?
There is no perfect way to model runtime state transitions in a type-safe manner. Your suggestion is a valid approach, but it has the downside that code can still hold a reference to a previous state ...
6
votes
Accepted
Is private global mutable state ever appropriate, namely when used to prevent API misuse?
Global state is not necessarily evil, even in functional languages.
However:
all this does is enforce a consistent ID generation per process. Multiple processes could still clash. You have to decide ...
6
votes
What to do when an aggregate is given a bad event?
The problem is that you're calling it an event. Events are reports of what has happened. They can't fail because they're over and done with. Since this hasn't happened yet, and it can still fail, it'...
6
votes
Stateful vs non-stateful app
If you are storing state on the server that is needed in order to process an incoming request from the client, then the server is stateful. Said another way, it has state that it stores and needs to ...
6
votes
Is global state really always bad?
Sometimes it's about what you make me read.
When I'm debugging something that relies on a mutable global variable (sorry, depends on) you force me to go read anything that writes to it to understand ...
6
votes
Are there any drawbacks to partial application?
This is an entirely normal and reasonable functional programming pattern.
But some people are not used to such patterns, and some abstractions are not worth it.
For example, because you are providing ...
5
votes
Accepted
3 tier application state handling
You can have different storage locations depending on your architecture.
You can store all the data on each of the sensors themselves, and the server requests them (and caches it) regularly. As a ...
5
votes
Accepted
What does it mean "state complects value and time"?
Wikipedia defines state as remembered information. It goes on to say that:
The set of states a system can occupy is known as its state space.
A stateful program (or system) is one in which ...
5
votes
Accepted
What's the proper way to think about state monads?
Functional programming encompasses a number of techniques, depending on who you ask:
higher-order functions,
closures,
referential transparency, and
making state explicit.
The value of using pure ...
5
votes
Accepted
Get value from UI element or from variable
You should have a "model"-"view" separation. It doesn't necessarily need to be some semi-formalized MV* pattern (e.g. MVC, MVP, MVVM, ad nauseam) or framework, but the idea of having some ...
5
votes
Changing bot application state (Starting → Started → Stopping → Stopped)
Definitively, an enum could be used for representing the state in a single variable and avoid some repetitions.
Take the following definition:
public enum State {Starting = 0, Started=1, ...
5
votes
Accepted
State Machine: what object is responsible for state transfer?
Sometimes it takes multiple objects for a whole abstraction.
The GoF state pattern is very general purpose. Each state needs to know only about successor states, so it can transition to them.&...
5
votes
Distributed cart state in microservices
I would not have the applied state associated with a coupon.
You need to check the coupons validity at two points.
When the customer 'applies' it to their basket.
This stops the customer adding used/...
5
votes
Handling user strategy choice over many strategy patterns
The strategy pattern is useful in situations where the public interface for each strategy object is uniform. Polymorphism is used in lieu of a complex decision structure. Based on your question, it ...
5
votes
Accepted
Global State, How To Do IT?
Work on your dependencies. Then inject concretes at runtime. This is what you are already doing, with your main.py providing the database inject into Steps API, and your don't have any circular ...
5
votes
Accepted
OO design - Process that relies on the current state of objects
There is a simple principle which helps you to avoid your program drifting into a Big-Ball-Of-Mud architecture: make a clear separation between getting the data and processing it.
I would omit the ...
4
votes
Is the benefit of the IO monad pattern for handling side effects purely academic?
My (limited) understanding of functional programming is that state/side effects
should be minimised and kept separate from stateless logic.
That's not just functional programming; that's usually a ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
state × 170design-patterns × 25
design × 18
object-oriented × 16
finite-state-machine × 15
functional-programming × 13
globals × 13
java × 11
javascript × 9
rest × 9
redux × 9
c# × 8
object-oriented-design × 8
c × 7
c++ × 6
reactjs × 6
session × 6
architecture × 5
python × 5
web-development × 5
variables × 5
immutability × 5
side-effect × 5
coding-style × 4
terminology × 4