The tag has no usage guidance.

learn more… | top users | synonyms (1)

2
votes
1answer
45 views

Preserving log of immutable Data Structure changes

I have large and complex immutable data structure (language is F#, but should be applicable to any language really) where I defined a lot of functions making changes and returning new instances of ds ...
0
votes
0answers
30 views

Versioning content in a No-SQL datastore

I am working on design a document management system and it has the following components : A Module has a content. A Document contains a list of Modules. A Document Collection contains a list of ...
1
vote
3answers
118 views

How do you create immutable objects with many parameters?

I need to create an immutable object but it requires several parameters to work like: class FooRepo { public string ConnectionStringName { get; } public string SchemaName { get; } public ...
0
votes
2answers
60 views

Is it a different object or the same object with an altered property (mutable or not)?

When I design the architecture of an application, I usually think about the nature of the objects and the interactions between them. The way I currently think about mutability is to ask myself if ...
0
votes
1answer
93 views

Why is ImmutableDictionary<TKey, TValue> implementing IDictionary<TKey, TValue>?

It looks like a weird design choice, because a Dictionary and an ImmutableDictionary are quite different write-wise. (Read-wise, they both implement IReadOnlyDictionary, which is fine*) In fact, the ...
1
vote
2answers
76 views

Passing and returning domain object in create method

We have this bean with two properties: ContainerImage + name (final, not null) + id (null) Then there is this method: ContainerImage create(ContainerImage containerImage); It receives ...
2
votes
1answer
156 views

Should I return Iterable or Enumeration in Java

In order to achieve better immutability, should my API return java.lang.Iterable<T> or java.util.Enumeration<E>? Since Iterable has a remove() method, one could say Enumeration is the ...
2
votes
6answers
252 views

How does immutability remove the need for locks when two threads are trying to update the shared state?

Okay so I read through this: Does immutability entirely eliminate the need for locks in multi-processor programming? And this was the main takeaway for me: Now, what does it get you? ...
3
votes
1answer
160 views

Is it pythonic to use properties to limit the mutability of class attributes (variables and methods)?

Some Explanation I'm somewhat new to python and to programming (I've been at it for a little over a year). I just recently discovered python properties, and I've been using them to limit the ...
6
votes
2answers
122 views

Returning Unmodifiable Collections only tees you up for runtime exceptions?

Seeing as how there are no distinct Unmodifiable Collections interfaces, aren't you just setting yourself up for runtime exceptions by returning Unmodifiable Collections from method invocations? ...
-2
votes
2answers
145 views

Java Integer - Immutable [closed]

I cannot understand the definition. Here's some code: Integer iW; for (iW = 1; iW < 4; iW++) System.out.println(iW); int i = iW; iW += 6; System.out.println(String.format("iW = %d, i = %d", iW ,...
6
votes
3answers
209 views

Doesn't returning a Collection as Unmodifiable / Immutable unnecessarily break method scope?

Let's say I create a Collection in an instance method. I do not assign that reference to any instance variables. Rather, I just return it to the invoker. Then, I exit. Now, the only thing with a ...
8
votes
1answer
1k views

Redux memory consumption [closed]

The Redux framework favors immutable state/pure function paradigm, which promotes creation of new state from the previous state in terms of the current action. The applicability of this paradigm is ...
-1
votes
1answer
242 views

In which cases and examples String in Java is not immutable? [duplicate]

If Strings are immutable in Java, why is the output of this code 2GB, instead of 1GB? class Laptop { String memory = "1GB"; } class Workshop { public static void main(String args[]) { ...
2
votes
2answers
168 views

Why does an immutable object in Scala need less memory than a mutable one?

In Programming in Scala, there is this statement: For instance an empty mutable map in its default representation of HashMap takes up about 80 bytes and about 16 more are added for each entry that’...
8
votes
2answers
346 views

Workaround for implementing operations on doubly linked or circular data structures in languages with immutable data

I would like to learn how to make graphs and perform some local operations on them in Haskell, but the question is not specific to Haskell, and instead of graphs we may consider doubly linked lists. ...
44
votes
6answers
5k views

Does immutability hurt performance in JavaScript?

There seems to be a recent trend in JavaScript towards treating data structures as immutable. For example, if you need to change a single property of an object, better to just create a whole new ...
3
votes
2answers
207 views

Should I add a layer to keep object always valid and immutable?

I am developing COM. A factory need to be initialized first by providing a ID. I can not pass arguments to IFactory instance via CoCreateInstance. So IFactory may need add a init method to be called ...
5
votes
1answer
210 views

Overriding == for immutable collections

Suppose I have a class that is a readonly collection or immutable objects, e.g. public class ReadOnlyInts : IReadOnlyCollection<int> { private readonly IReadOnlyCollection<int> ...
1
vote
0answers
105 views

Finding Parent Node in Directed Acyclic Graph

I've implemented a structural sharing algorithm for creating Clojure style persistent trees, but it relies on the child node knowing its own parent. function fork return new Node children: this....
3
votes
1answer
84 views

Big-O for Immutable Trees

How would you calculate the time and space complexity for a tree algorithm that creates a copy of a tree, but reuses as much of the original tree as possible? For example, A /|\ B C G /|\ D ...
24
votes
7answers
3k views

Is there any practical way for a linked node structure to be immutable?

I decided to write a singly-linked list, and had the plan going in to make the internal linked node structure immutable. I ran into a snag though. Say I have the following linked nodes (from previous ...
0
votes
1answer
201 views

Immutable class with behavior

I've just finished Effective Java and I loved it. I'm trying to refactor one of my programs to take advantage of what I've learned, and I have a lot of questions regarding immutability. My program is ...
22
votes
4answers
4k views

How do I handle setters on immutable fields?

I have a class with two readonly int fields. They are exposed as properties: public class Thing { private readonly int _foo, _bar; /// <summary> I AM IMMUTABLE. </summary> ...
6
votes
4answers
330 views

Is guaranteeing immutability a justification for exposing a field instead of a property?

The general guidance for C# is to always use a property over a public field. This makes sense- by exposing a field, you're exposing a lot of implementation detail. With a property, you encapsulate ...
3
votes
2answers
295 views

Java: using final keyword only on method parameters that expect immutable objects? [closed]

I came across the interesting topic about final method parameters and that they essentially don't provide much advantages. I wondered if it would be sensible to mark only those method parameters as ...
0
votes
4answers
253 views

Is collection object better being immutable? [closed]

As per this link, it is an advice that: A good object should never change his encapsulated state. Remember, an object is a representative of a real-life entity, and this entity should stay the ...
2
votes
2answers
274 views

Is this the solution to static inheritance?

I've seen a lot of posts recently on why Singletons should be avoided. However, I can't see any of those problems with the following solution to a common problem: static inheritance. For example, I ...
2
votes
1answer
128 views

Library OSes vs Unikernels

My understanding of a Hypervisor & Virtual Machines is that the hypervisor is a program (either running on top of a host OS, or running bare metal as the host) that leverages binary-compatible ...
2
votes
1answer
219 views

C++: Make classes immutable or compatible with STL containers

Making types immutable is often desireable, especially for multi-threaded applications. There's no need to worry about concurrent access and no need for any synchronization. The common STL containers ...
3
votes
2answers
137 views

Dealing with states in a immutable approach [closed]

I want to know how to deal when you have some states in a program, with functions that depends on them, but with a immutable approach. I read some examples and questions, but all focus in a small ...
4
votes
2answers
192 views

Is it considered good practice to declare base interfaces without mutators, supplying mutatators in a sub-interface

I asked a question on StackOverflow on how to properly implement an ImmutableMap that abides by the SOLID principles. Due to Java's Map interface containing put and putAll, it violates the interface ...
3
votes
3answers
377 views

How to make complex objects immutable?

The example I'm about to give is for the PHP language, but I think this scenario applies to most languages. Let's say I have an object called Response and I want it to be immutable. Every method ...
5
votes
1answer
577 views

Mutable with logic inside or immutable with logic outside?

I know immutable objects are preferred to mutable objects for reasoning and maintenance. But in occasions making a class immutable have some costs, let me explain it with a simple example: class ...
2
votes
2answers
297 views

Designing entities that should be mutable through the GUI but protected from programmer error

I have a set of entities, for now represented by very simple classes (further simplified for this example): public class Item { public string Name { get; private set; } public double ...
2
votes
5answers
418 views

Is it bad or good to wrap mutable objects in immutable containers?

If I have parts of code that need to mutate the underlying data structure but then others that consume, not mutate the structure, is it good practice to create a wrapper which does not expose mutation ...
3
votes
4answers
311 views

How to refactor my project to have less mutable objects? [duplicate]

There seems to be a trend towards immutable objects, and functional programming. I recently got aware about the benefits of immutability. However, I am not very familiar with this style of programming....
4
votes
1answer
123 views

How would I isolate changes to mutable state if I need to run two queries to get the final result?

I'm working on some code that takes search criteria from a Rest API and uses it to query a remote API to return results. As an exercise, I wanted to try to separate all state changes to one place, as ...
6
votes
2answers
4k views

How should I annotate, that a class is immutable in Java?

I recently stumbled upon how useful immutable objects are and that e.g. if you pass elements to a constructor and your class should be immutable, you have to copy these elements if they are not ...
3
votes
1answer
287 views

Why do mainstream OO languages not have immutability on class-level built-in? [duplicate]

I regularly write classes which can only have immutable instances, much like string. I am wondering why Java or C# or VB.NET don't have immutability built-in into the language? That way, I can ...
4
votes
3answers
356 views

Batching immutable object changes?

With immutable models, what would be the best way to batch several changes? For example, let's have a Book that is immutable. I need to change both title and year. I could change one by one, but that ...
1
vote
1answer
313 views

Tell, Don't Ask and Immutability in a non-directional network

I'm working on a small project in which I'm attempting to practice relatively strict adherence to two ideas: Tell, don't ask (TDA) Immutability The main concept in this project is a Map (as in a ...
3
votes
3answers
487 views

Immutable objects [closed]

Looking at questions such as these If immutable objects are good, why do people keep creating mutable objects? What are the drawbacks of immutable types? At what point do immutable classes become a ...
0
votes
0answers
231 views

Controllers passing Request objects to backend logic that forward Request data: Good or Bad?

Currently working on a server-side front-end Scala Play app that does a lot of grabbing of HTML snippets and JSON from many other web apps before piecing everything together and sending it in a ...
7
votes
4answers
559 views

“Immutable” interfaces

I am confused about the notion of immutability. Consider the following structure of a simplistic calculator: Here are the interfaces: interface IOperationalInterface { int Sum(int a, int b); } ...
50
votes
8answers
4k views

Is immutability very worthwhile when there is no concurrency?

It seems that thread-safety is always/often mentioned as the main benefit of using immutable types and especially collections. I have a situation where I would like to make sure that a method will ...
1
vote
2answers
568 views

Do immutable objects that constantly change impact memory/performance?

I'm writing a program that goes into a loop and keeps changing the state of some models (similar to a game). Naturally, many things are mutable. However, I'm also writing some classes that are ...
0
votes
3answers
160 views

Writing a method to 'transform' an immutable object: how should I approach this?

(While this question has to do with a concrete coding dilemma, it's mostly about what's the best way to design a function.) I'm writing a method that should take two Color objects, and gradually ...
0
votes
1answer
187 views

Clean way to use mutable implementation of Immutable interfaces for encapsulation

My code is working on some compost relationship which creates a tree structure, class A has many children of type B, which has many children of type C etc. The lowest level class, call it bar, also ...
5
votes
3answers
323 views

Decreasing vars in Scala programs

I have been studying scala for the past week or so and the ideologies associated with it and functional programming in general. As expected, the leap from imperative to functional programming is not ...