The tag has no usage guidance.

learn more… | top users | synonyms

219
votes
24answers
10k views

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 ...
14
votes
11answers
2k views

What is better IllegalStateException or silent method execution? [closed]

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 ...
6
votes
1answer
100 views

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 ...
2
votes
1answer
80 views

Possible DRY with Pausing Mechanism

Background I am currently working on the architecture for a future software design. The design is one long running task (hours-long) with thousands of sequential calls to various libraries. I ...
0
votes
0answers
43 views

How to save the differences between objects which are the result of random changes?

I keep a state object of the following form: class State { int num1, num2; List<String> strings; MyObject myObject; // A class I wrote // etc. } The state changes many times ...
7
votes
1answer
189 views

Should I use a Status field or rely on calculations?

A bit long, but the overall the question is: Should I have a status field in the table, or should I calculate the status in-memory from other information in the record? What are the pro/cons of ...
5
votes
1answer
444 views

Are we abusing static methods?

A couple of months ago I started working in a new project, and when going through the code it stroke me the amount of static methods used. Not only utility methods as ...
6
votes
2answers
182 views

Idiomatic way to write JavaScript class that maintains state and tells you when that state has changed

I am an experienced C++ developer but new to JavaScript. I want to write an ES6 JavaScript class that maintains state. How do I tell when state has changed? I can think of two ways to do this. One ...
2
votes
5answers
553 views

API design dilemma: to REST or not to REST

I'd like to design a REST API supporting: Login Temporary token generation The reason being there are a number of client-side REST libraries that would speed up development if used, as they take ...
3
votes
1answer
60 views

Interactive review of data in modal before inserting in db

I'm looking for a conceptual approach to a problem. I'm building a web app that imports data from a source I don't control. The data quality is pretty high, but occasionally, the data does not make ...
16
votes
2answers
1k views

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 ...
2
votes
1answer
236 views

What is internal state and is there a difference between state and internal state

Ok, this question has been asked before, but it's still not clear to me. What exactly is internal state? So far state is clear to me: Functions contain behavior, variables have state, values don't. ...
0
votes
1answer
85 views

sessions and stateless rest

I believe this question has been discussed to death. I was reading up on REST and it says that it has to be stateless. Yes i do understand there are application states and resource states. Taking ...
8
votes
3answers
306 views

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 ...
1
vote
3answers
106 views

Cleanest way to represent three states, where one can hold a Key/Value pair, and the other two are empty markers

I'm writing a Hash Table that uses linear probing to resolve collisions. I looked over how linear probing works, and it seems like to allow for deletions, I can't simply remove an element, since that ...
1
vote
1answer
96 views

Best practices for tracking multiple pieces of data in a program

I have a project in C (don't ask why but it needs to be in C), where I need to track multiple pieces of data and commands for different modules. Some actions that the program will take depend on the ...
4
votes
1answer
119 views

Should I try to separate state from implementation?

Right now I'm working with some code that combines state and operations. It looks something like this (note: doesn't actually deal with Cars/Trucks. I'm abstracting the business logic here, and ...
1
vote
2answers
217 views

Is there a hashCode()-like method that can be used for state checking?

I thought up a simple and efficient way to combine states with events to make event handling more efficient. My idea of state checking involves State objects that hold reference to mutable variables ...
2
votes
1answer
300 views

React and simple UI state

I'm starting to playing around with React and have a basic question regarding state. I understand that in React state should only contain data which may change and cannot be computed from elsewhere, ...
1
vote
1answer
148 views

Checking for valid state inside function or outside [closed]

This is a common occurrence in programming and is language agnostic, you have a function that needs to do something but in only in some cases. Maybe it's a feature-toggle, maybe it's a function that ...
3
votes
3answers
539 views

How to model state of leaving/entering home

I have two sensors: One detecting if the door is open or closed, another if movement has been detected in the corridor. I want to detect if the person has left or entered home. Usually the person has ...
0
votes
1answer
55 views

How does non-interruptive autosave work?

Many apps save state and progress automatically in the background. Mobile apps save what page you're on even after the apps are cleared out of RAM. OneNote and Word for iOS save documents ...
6
votes
4answers
568 views

Does internal state “leak” when it influences externally-visible behavior?

I have a method (in C++) which generates a value based on a parameter and the parameters from previous calls. Calling it more than once with the same parameter may generate different values each time. ...
3
votes
1answer
726 views

How to avoid global state without large function signatures?

So, there are some good answers to this question, namely: Why is Global State so Evil? I have a specific question about the alternatives Mikera proposed as the answer with the second most up-votes. ...
0
votes
2answers
89 views

How to predict a future simulation state

We have a program that combines the simulation of an aircraft system and predefined pedagogical scenarios for trainee pilots to learn how to use this system. When we follow the normal scenario, ...
2
votes
0answers
49 views

Angular UI's $StateProvider [duplicate]

I was thinking of using Angular UI, and specifically its $StateProvider, which makes it easy to create nested views, in my next application. Until now, I have been using vanilla Angular's ngInclude ...
9
votes
4answers
2k views

What is meant by “OOP hides the state”? [closed]

In one of many anti-OOP rants on cat-v.org I found a passage by Joe Armstrong raising several objections against the OOP model, one of which was the following: Objection 4 – Objects have private ...
3
votes
2answers
144 views

System state design composition

Consider the following Java code: public class HumanStateImpl implements HumanState { private boolean alive; private Color skinColor; // getters and setters, other state fields ...
2
votes
2answers
223 views

Why must essential mutable derived data have an inverse function?

I was reading the paper Out of the Tar Pit authored by Ben Moseley and Peter Marks when I came across the following section on page 25 regarding essential mutable derived data: Essential Derived ...
8
votes
4answers
8k views

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? ...
1
vote
0answers
129 views

Looking for design pattern to represent shared state in music sequencer

I like to give lots of context, but also to state the basic question up top as concisely as possible. Feel free to read a little or a lot. I'm working on a music sequencer, and have been happy so far ...
1
vote
1answer
212 views

Can we consider a clients interaction with a web server to be stateful if the web server maintains state via session variables or cookies?

A little confused with the notion of stateful/stateless architectures. Forgive me if I'm unclear. Questions: Can we consider a clients interaction with a web server to be stateful if the web server ...
2
votes
2answers
151 views

Can the Jacquard loom be considered stateless?

Can the Jacquard loom, pictured below complete with its chains of paper cards be considered stateless? As far as I can tell I can tell, each operation is not dependant on the previous. Or did it ...
1
vote
3answers
232 views

A pattern to “atomically” update a pair of objects

Is there a standard pattern in OOP to kind of "atomically" update a pair of objects, like a pair of bank accounts on a transaction? I would like to have somehow a single public method exposed that ...
1
vote
1answer
727 views

State design pattern: best implementation for my case?

Me and a mate have a discussion about what would be the best way to implement the pattern state for managing several screens for an application we are developing. We have a ScreenManager (I guess the ...
3
votes
3answers
460 views

“state” or “status”? When should a variable name contain the word “state”, and when should a variable name instead contain the word “status”? [closed]

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 ...
16
votes
2answers
446 views

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 ...
1
vote
1answer
273 views

How to test issues in a local development environment that can only be introduced by clustering in production?

We recently clustered an application, and it came to light that because of how we're doing SSL offloading via the load balancer in production it didn't work right. I had to mimic this functionality on ...
4
votes
3answers
379 views

Throwing exception from a property when my object state is invalid [duplicate]

I am aware that for the general case, the answer to "should I throw an exception from a property" is "generally don't, but in some special circumstances it is OK to do so". There is a Microsoft ...
13
votes
5answers
890 views

Can *any* program task be expressed without state?

This is a theoretical question, but after many years of programming in what I now realize is "normal" imperative technique, using C++ mainly, I've discovered this other world of functional ...
2
votes
1answer
176 views

State pattern long state class names

I am using state pattern on 28 states in my application. The states are for membership cards that has 7 major states, there are 4 boolean attributes for the membership card that actually affects the ...
0
votes
2answers
172 views

Memento with optional state?

EDIT: As pointed out by Steve Evers and pdr, I am not correctly implementing the Memento pattern, my design is actually State pattern. Menu Program I built a console-based menu program with multiple ...
-1
votes
1answer
907 views

Java: How to manage UDP client-server state

I am trying to write a Java application that works similar to MapReduce. There is a server and several workers. Workers may come and go as they please and the membership to the group has a soft-state. ...
16
votes
4answers
3k views

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 ...
1
vote
1answer
1k views

How to implement session state in a backend web application?

When using a non-MVC service-oriented/Interactor pattern approach to decoupled system architecture, how is session state implemented? I've been thinking of building the frontend of an application ...
3
votes
4answers
320 views

In Scheme, what is formally a program's state?

I think i've understood more or less what a parsed Scheme program looks like (a binary tree with atomic values on the leaves, if i have understood correctly). Can anybody please define to me, or give ...
4
votes
2answers
300 views

What is the preferred way of communicating between applications on the same system?

I'm designing a system that is built on several small applications written in python, some of these will be services and others will be programs that only run during special situations. What I need to ...
3
votes
1answer
675 views

script engine with no global environment (java)

I am curious about how global variables are handled by script engines. I am looking for a script engine that does not preserve the state of global variables upon invocation. Are there such engines out ...
3
votes
1answer
259 views

On Developing Web Services with Global State

I'm new to web programming. I'm more experienced and comfortable with client-side code. Recently, I've been dabbling in web programming through Python's Google App Engine. I ran into some difficulty ...
2
votes
1answer
364 views

Validation and Error Generation when using the Data Mapper Pattern

I am working on saving state of an object to a database using the data mapper pattern, but I am looking for suggestions/guidance on the validation and error message generation step (step 4 below). ...