Skip to main content
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 ...
Robert Harvey's user avatar
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: { ...
Greg Burghardt's user avatar
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() ...
candied_orange's user avatar
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 ...
amon's user avatar
  • 136k
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 ...
Telastyn's user avatar
  • 110k
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 ...
Doc Brown's user avatar
  • 220k
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 ...
Flater's user avatar
  • 59.5k
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 ...
Alex's user avatar
  • 3,952
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 ...
amon's user avatar
  • 136k
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 ...
Telastyn's user avatar
  • 110k
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 ...
slepic's user avatar
  • 189
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 ...
Christophe's user avatar
  • 82.2k
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 ...
JimmyJames's user avatar
  • 30.9k
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 ...
JacquesB's user avatar
  • 62.3k
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 ...
amon's user avatar
  • 136k
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'...
candied_orange's user avatar
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 ...
jfriend00's user avatar
  • 3,607
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 ...
candied_orange's user avatar
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 ...
amon's user avatar
  • 136k
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 ...
gbjbaanb's user avatar
  • 48.8k
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 ...
Erik Eidt's user avatar
  • 34.8k
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 ...
amon's user avatar
  • 136k
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 ...
Derek Elkins left SE's user avatar
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, ...
Christophe's user avatar
  • 82.2k
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.&...
Erik Eidt's user avatar
  • 34.8k
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/...
Ewan's user avatar
  • 84.4k
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 ...
Greg Burghardt's user avatar
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 ...
Arseni Mourzenko's user avatar
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 ...
Doc Brown's user avatar
  • 220k
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 ...
cjs's user avatar
  • 783

Only top scored, non community-wiki answers of a minimum length are eligible