The tag has no wiki summary.

learn more… | top users | synonyms (1)

0
votes
1answer
94 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
63 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
293 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
30 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
469 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); } ...
48
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
249 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
135 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
119 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
206 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 ...
7
votes
3answers
362 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
199 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
170 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 ...
25
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
186 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
198 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
174 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
1k 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 ...
30
votes
5answers
5k 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
394 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
534 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 ...
2
votes
6answers
9k 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. ...
16
votes
3answers
5k 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
662 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
322 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
306 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
380 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
262 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
299 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
585 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
710 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 ...
6
votes
2answers
449 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
224 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
494 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 ...
1
vote
2answers
5k 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 ...
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 ...
3
votes
3answers
443 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
693 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 ...
136
votes
23answers
39k 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 ...
8
votes
5answers
4k 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
485 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
76 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 ...
4
votes
2answers
919 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 ...
5
votes
2answers
571 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 ...