119 votes

How are globals any different from a database?

First, I'd say that the answer you link to overstates that particular issue and that the primary evil of global state is that it introduces coupling in unpredictable ways that can make it difficult to ...
Jules's user avatar
  • 17.8k
105 votes
Accepted

How to keep applications stateless

"web applications should be stateless" should be understood as "web applications should be stateless unless there is a very good reason to have state". A "shopping cart" is a stateful feature by ...
Philipp's user avatar
  • 23.3k
68 votes

How to keep applications stateless

It's true that web applications should be stateless. However, session variables, cookies, and tokens don't violate this when they are all stored on the client (web browser). They can be parameters in ...
candied_orange's user avatar
45 votes

How are globals any different from a database?

I'd offer a few observations: Yes, a database is global state. In fact, it's a super-global state, as you pointed out. It's universal! Its scope entails anything or anyone that connects to the ...
svidgen's user avatar
  • 14.7k
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
38 votes
Accepted

What is better IllegalStateException or silent method execution?

There is no rule. It's entirely up to how you want to make your API "feel." Personally, in a music player, I think a transition from the state Stopped to Stopped by means of the method Stop() is a ...
MetaFight's user avatar
  • 11.6k
33 votes

How to keep applications stateless

web applications should be stateless Nonsense. Web requests should be stateless. Or more accurately, web requests are stateless. But, saying that a whole application should be stateless is complete ...
svidgen's user avatar
  • 14.7k
27 votes
Accepted

Are we abusing static methods?

What's the difference between new CustomerReceiptCreator().createReceipt() and CustomerReceiptCreator.createReceipt()? Pretty much none. The only significant difference is that the first case has ...
Winston Ewert's user avatar
23 votes

How are globals any different from a database?

I disagree with the fundamental claim that: When your program is working with data from a database, you don't care if other code in your system is changing it, or even if an entirely different ...
Michael Anderson'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
22 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

How are globals any different from a database?

The point that the sole reason global variables can't be trusted since the state can be changed somewhere else is, in itself, not reason enough to not use them, agreed (it's a pretty good reason ...
Jeffrey Sweeney's user avatar
18 votes

What is better IllegalStateException or silent method execution?

There are two distinct kinds of actions one may wish to perform: Simultaneously test that something is in one state, and change it to another. Set something to a particular state, without regard for ...
supercat's user avatar
  • 8,445
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
  • 134k
16 votes

How to keep applications stateless

Statefulness is not necessarily a bad thing, but you need to understand the difference between stateful and stateless apps. In short, stateful apps maintain information about the current session, and ...
Robert Munn's user avatar
  • 1,301
13 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
  • 109k
12 votes
Accepted

Should I use a Status field or rely on calculations?

Do you think that is wise to skip the status field? Yes. For several reasons. The status field is a cached value of something that can be computed. Caching is an optimization, the premature ...
Erik Eidt's user avatar
  • 33.8k
11 votes
Accepted

Is there a good formal pattern to manage state in MVVM?

I think I know what you mean. Basically you solve the problem by adding either a 'controller' or a 'master' viewmodel (excuse psudocode) ie public class MasterVM { public ChildVM View1 {get;set;}...
Ewan's user avatar
  • 75.8k
11 votes

What is better IllegalStateException or silent method execution?

The purpose of exceptions isn't to signal that something bad has happened; it's to signal that Something bad has happened that I don't know how to fix here that the caller, or something up the ...
Mason Wheeler's user avatar
11 votes

How are globals any different from a database?

But when I look at that, I can't help but think that that's a really weak explanation, because how is that any different from working with data stored in a database? Or any different from a working ...
David Hammen's user avatar
  • 8,331
11 votes

What is better IllegalStateException or silent method execution?

There is no general rule. In this specific case, the intention of the user of your API is to stop the player from playing the media. If the player is not playing the media, the MediaPlayer.stop() may ...
kmaczuga's user avatar
  • 111
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
  • 208k
10 votes

Does object-oriented programming allows side effects and state changes?

There is no universal definition of OOP. It is therefore difficult to make a statement like “OOP is stateful”. There are both examples where OOP involves state and examples where OOP is used without ...
amon's user avatar
  • 134k
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
  • 49.9k
9 votes
Accepted

Stateful vs stateless (non web app) applications

Technically, computers always have state, even if it is just program state. So, in order to determine stateful/stateless as we commonly talk about, you have to have some notion of an interaction, ...
Erik Eidt's user avatar
  • 33.8k
9 votes
Accepted

UML "direct substate" vs "transitively nested substate"

Direct substate is a one level substate of a state Transitively nested substate is a substate of a substate (any levels down) Consider this diagram: For active state direct substates are filing ...
Ister's user avatar
  • 849
8 votes

How are globals any different from a database?

I think that the quoted explanation oversimplifies the issue to the point where the reasoning becomes ridiculous. Of course, the state of an external database contributes to the global state. The ...
5gon12eder's user avatar
  • 7,196
8 votes

How are globals any different from a database?

As a software engineer working predominantly with embedded firmware, I'm almost always using global variables for anything going between modules. In fact, it's best practise for embedded. They are ...
Graham's user avatar
  • 2,006
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,922

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