The tag has no wiki summary.

learn more… | top users | synonyms (1)

2
votes
5answers
256 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
164 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 ...
4
votes
1answer
103 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 ...
3
votes
1answer
182 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 ...
2
votes
1answer
195 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 ...
-3
votes
1answer
125 views

What is immutable by default in Java? [closed]

While trying to grasp copying/copy constructors, and noticed that some things seem to be immutable by default (Strings, and Integers), while everything else is mutable by default. That leaves me ...
4
votes
3answers
243 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 ...
0
votes
1answer
134 views

How to Understand the concept of Immutablity in Functional Programming [duplicate]

I have come across several sources that say that immutability is a concept that is followed in functional programming. I have come across this concept when looking at collections in Scala where a new ...
1
vote
1answer
112 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
337 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
63 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
485 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); } ...
49
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
300 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
138 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
131 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
241 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 ...
8
votes
3answers
401 views

Object Identity and Mutability

I was reading a proposal for value types in Java, and I came across this sentence: "Object identity serves only to support mutability, where an object’s state can be mutated but remains the same ...
1
vote
2answers
221 views

What's the difference of an object being final and an object being immutable in java?

final String str = "do not change me"; str = "why not?"; //it will result in compile time error saying that final fields can not be re-assigned once created i.e. the reference cannot be changed ...
2
votes
1answer
298 views

Local Updates in Persistent/Immutable Data Structures

I'm getting into ReactJS and am intrigued but also confused about persistent data structures. I love the idea, but I'm not sure how to take my MV*, Mutable, Observable Bindings experience in designing ...
28
votes
7answers
2k views

Complete immutability and Object Oriented Programming

In most OOP languages, objects are generally mutable with a limited set of exceptions (like e.g. tuples and strings in python). In most functional languages, data is immutable. Both mutable and ...
0
votes
1answer
191 views

Read-only class properties [duplicate]

When is recommended to use read-only properties -- if the language allows me? Are public read-only properties meant to replace getter methods or at least the Magic Methods like what is available as ...
5
votes
2answers
217 views

Language that embraces mutable state? [closed]

There seems to be a trend towards immutable objects, and pure functional programming. While I recognize the benefits, I find it hard to apply these principles to GUI programming, for example. But I ...
1
vote
1answer
175 views

Handling array passed to object at creation

When creating my object I pass it an array of a row from my database. (everything in the array we will need, disregarding unnecessary elements at sql query level) When I need to access certain array ...
2
votes
1answer
2k views

Example of a javascript app using immutable data structures? [closed]

JavaScript is functional but not in a strict sense. It does not rely on immutable data and side-effect free functions. There are a few libs that provide immutable data structures, so I believe it ...
39
votes
5answers
8k views

Why doesn't Java 8 include immutable collections?

The Java team has done a ton of great work removing barriers to functional programming in Java 8. In particular, the changes to the java.util Collections do a great job of chaining transformations ...
5
votes
2answers
416 views

Is this a correct implementation of an Immutable class in Java?

public final class ImmutableClass { private StringBuffer name; public ImmutableClass(StringBuffer name) { this.name=name; } public StringBuffer getName() { return ...
6
votes
1answer
680 views

Why appending to a list in Scala should have O(n) time complexity?

I am learning Scala at the moment and I just read that the execution time of the append operation for a list (:+) grows linearly with the size of the list. Appending to a list seems like a pretty ...
3
votes
7answers
16k views

Understanding the difference between mutable and immutable classes

I faced this question in one interview. I explained that String is immutable and StringBuffer is mutable class. I don't know very much about mutable and immutable and also don't know the exact answer. ...
18
votes
3answers
6k views

When is it NOT good to use actors in akka/erlang?

I've been working with akka for 7-8 months now daily. When I started, I would be working on applications and notice that actors would be used basically anywhere once inside the actor system for ...
5
votes
4answers
829 views

C# Delegates are immutable - but why does that matter?

This is a followup question to this other question. Background Working from the MSDN Delegates Tutorial (C#), I see the following: Note that once a delegate is created, the method it is ...
1
vote
1answer
361 views

Immutable Data Structure For Time Series Data

I'm wondering what the best data structure (for storing data on disk) is for storing immutable time-series data (99% of the data is truly immutable, the 1% is metadata that is separate from the ...
2
votes
2answers
368 views

Is it possible to represent mutation of object-graph efficiently with immutable states?

I am practicing using of immutable object in C++. My personal goal is representing generic object graph (in heap) with sequence of immutable graphs. Building the multi-version graph itself isn't that ...
3
votes
1answer
478 views

Mutable and Immutable version of Collection implementations or both stuffed into one via .makeImmutable()

I am currently working on a collection implementation in JavaScript. I need a mutable and an immutable version of that. So what I thought of first was something like: Collection MutableCollection ...
1
vote
4answers
264 views

Is there a concept of a variable with phases of initialization: uninitialized, initializing, immutable?

I was looking at this thread on Stack Overflow and thinking about the functional programming I've been learning, and how immutability is so key there, and it occured to me that maybe some language has ...
1
vote
2answers
353 views

Making a class pseudo-immutable by setting a flag

I have a java project that involves building some pretty complex objects. There are quite a lot (dozens) of different ones and some of them have a HUGE number of parameters. They also need to be ...
7
votes
4answers
646 views

What are the drawbacks of immutable types?

I see myself using more and more immutable types when the instances of the class are not expected to be changed. It requires more work (see example below), but makes it easier to use the types in a ...
6
votes
2answers
1k views

Is Haskell/Clojure actually unsuited for dynamic systems such as particle simulation?

I've been told in previous questions that functional programming languages are unsuited for dynamic systems such as a physics engine, mainly because it's costly to mutate objects. How realistic is ...
-1
votes
4answers
858 views

Immutable vs mutable object as returned parameter for class method [closed]

There is a class method (static method) in which I create and build some object. And for filling that object, I create it as mutable object. My mutable object is a subclass of immutable object. So ...
7
votes
2answers
460 views

When is it inappropriate to make objects immutable?

I have a class which represents an entity object in our system (for sake of argument, a Customer object) public class Customer() { private int id; private String name; ... // 30+ fields ...
5
votes
2answers
236 views

method to allow me ability to freely modify my classes, but make them immutable to others?

I am creating the model part of an MVC architecture. My one class will provide all the accesses to allow one to fetch system state. I want most of this state to be immutable as it shouldn't be ...
6
votes
5answers
2k views

When and why would we use immutable pointers?

In Java, the String object is both immutable and also a pointer (aka reference type). I'm sure there are other types/objects which are both immutable and a pointer as well and that this extends ...
3
votes
5answers
2k views

A string is immutable, so why are they not all constants?

The string type is immutable. We can use the const keyword with strings in high level language like .NET. My understanding of 'const' means constant (it remains the same, we can't change the value). ...
4
votes
3answers
584 views

How Immutable Sets are Manipulated

When working with an immutable set or map, like the ones found in many functional programming languages, operations that would otherwise modify the container generate a new container instead. I know ...
23
votes
4answers
2k views

Do not declare interfaces for immutable objects

Do not declare interfaces for immutable objects [EDIT] Where the objects in question represent Data Transfer Objects (DTOs) or Plain Old Data (PODs) Is that a reasonable guideline? Up to now, I've ...
2
votes
2answers
6k views

How to increase the efficiency of an Immutable Queue in java?

I have been developing an Immutable queue in java, but the version I have developed is supposedly slow and I have been suggested to create a faster version of the same and I have no idea as to how to ...
5
votes
4answers
1k views

Are immutable/stateless singletons bad?

Lately there have been some kind of revolution against singletons, but is there something wrong with them if they are stateless? I know the overuse talk and all... this applies to everything not just ...
3
votes
4answers
1k views

Immutable Method in Java

In Java, there is the final keyword in lieu of the const keyword in C and C++. In the latter languages there are mutable and immutable methods such as stated in the answer by Johannes Schaub - litb ...
24
votes
5answers
3k views

Does immutability entirely eliminate the need for locks in multi-processor programming?

Part 1 Clearly Immutability minimizes the need for locks in multi-processor programming, but does it eliminate that need, or are there instances where immutability alone is not enough? It seems to ...
3
votes
3answers
519 views

Internal Mutation of Persistent Data Structures

To clarify, when I mean use the terms persistent and immutable on a data structure, I mean that: The state of the data structure remains unchanged for its lifetime. It always holds the same data, ...