The tag has no wiki summary.

learn more… | top users | synonyms (1)

1
vote
2answers
152 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 ...
1
vote
0answers
51 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 ...
24
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
178 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
170 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 ...
0
votes
1answer
109 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 ...
1
vote
1answer
255 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 ...
24
votes
5answers
2k 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
363 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
347 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 ...
1
vote
6answers
3k 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. ...
13
votes
3answers
2k 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
523 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
279 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
197 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
271 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
258 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
243 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 ...
2
votes
4answers
362 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
944 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
509 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 ...
5
votes
2answers
398 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
210 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 ...
4
votes
5answers
1k 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 ...
2
votes
5answers
1k 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
367 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 ...
22
votes
4answers
1k 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 ...
1
vote
2answers
3k 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 ...
4
votes
4answers
913 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
662 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 ...
23
votes
5answers
2k 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 ...
2
votes
3answers
359 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, ...
5
votes
4answers
631 views

Is there any functional difference between immutable value types and immutable reference types?

Value types are types which do not have an identity. When one variable is modified, other instances are not. Using Javascript syntax as an example, here is how a value type works. var foo = { a: 42 ...
112
votes
22answers
27k views

If immutable objects are good, why do people keep creating mutable objects?

If immutable objects¹ are good, simple and offer benefits in concurrent programming why do programmers keep creating mutable objects²? I have four years of experience in Java programming and as I see ...
7
votes
5answers
3k views

Difference between immutable and const

I've often seen the terms immutable and const used interchangeably. However, from my (little) experience, the two differ a lot in the 'contract' they make in code: Immutable makes the contract that ...
13
votes
7answers
444 views

How does one decide if a data object type should be designed to be immutable?

I love the immutable "pattern" because of its strengths, and in the past I have found it beneficial to design systems with immutable data types (some, most or even all). Often when I do so, I find ...
3
votes
1answer
69 views

Is there any scenario where it's useful to keep mutable properties cached in domain objects for anything else than informational purposes?

Usually in a domain model, you'll have objects, and those objects will have properties that are mutable and properties that are immutable - for instance, a instance id/name will be immutable, while ...
3
votes
2answers
743 views

What's wrong with mutability and can it be desirable? [duplicate]

Possible Duplicate: At what point do immutable classes become a burden? This is something I never understood. When learning C++, for instance, I had lots of headaches with const issues, as ...
4
votes
2answers
493 views

Immutable structures and deep composition hierarchy

I'm developing a GUI application, heavily working with graphics - you can think about it as a vector editor, for the sake of the example. It is very tempting to make all data structures immutable - so ...
15
votes
4answers
326 views

Is there a specific design strategy that can be applied to solve most chicken-and-egg problems while using immutable objects?

Coming from a OOP background (Java), I'm learning Scala on my own. While I can readily see the advantages of using immutable objects individually, I'm having a hard time seeing how one can design a ...
14
votes
8answers
2k views

Favoring Immutability in Database Design

One of the items in Joshua Bloch's Effective Java is the notion that classes should allow mutation of instances as little as possible, and preferably not at all. Oftentimes, the data of an object is ...
12
votes
7answers
788 views

Getting My Head Around Immutability

I'm new to object-oriented programming, and one concept that has been taking me a while to grasp is immutability. I think the light bulb went off last night but I want to verify: When I come across ...
2
votes
3answers
679 views

What are the consequences of immutable classes with references to mutable classes?

I've recently begun adopting the best practice of designing my classes to be immutable per Effective Java [Bloch2008]. I have a series of interrelated questions about degrees of mutability and their ...
29
votes
2answers
1k views

What did Alan Kay mean by “assignment” in The Early History of Smalltalk?

I have been reading The Early History of Smalltalk and there are a few mentions of "assignment" which make me question my understanding of its meaning: Though OOP came from many motivations, two ...
49
votes
4answers
2k views

Why were Java collections implemented with “optional methods” in the interface?

During my first implementation extending the Java collection framework, I was quite surprised to see that the collection interface contains methods declared as optional. The implementer is expected ...
11
votes
4answers
841 views

Functional Programming — Immutability

I am trying to understand dealing with immutable data in FP (specifically in F#, but other FP’s are ok as well) and break the old habit of state-full thinking (OOP style). A part of the selected ...
7
votes
7answers
2k views

At what point do immutable classes become a burden?

When designing classes to hold your data model I've read it can be useful to create immutable objects but at what point does the burden of constructor parameter lists and deep copies become too much ...
12
votes
9answers
2k views

Do immutable objects and DDD go together?

Consider a system that uses DDD (as well: any system that uses an ORM). The point of any system realistically, in nearly every use case, will be to manipulate those domain objects. Otherwise there's ...