Immutability is the inability to modify data after it has been created. Modifications are instead made by copying the data. A property of immutable data is that it is *referentially transparent*.

learn more… | top users | synonyms

22
votes
8answers
2k views

Immutable objects in Java

I just finished studying immutable objects and their advantages so I thought I'd create one of my own. Here is my employee class that extends a person class. It is not mutable since I have getters to ...
3
votes
1answer
51 views

Immutable Matrix

I'm writing implementations of some numerical methods to solve linear equations systems, those implementations use the following Matrix class. I'm trying to get this class immutable, due to that the ...
2
votes
2answers
56 views

Replacing an F# loop over a mutable variable by an immutable approach

Consider: let mutable m' = m while m' % i = 0L do m' <- m' / i I've refactored it into: ...
10
votes
1answer
73 views

Immutable Fraction class

Inspired by this question: Fraction class implemented in Objective-C, I have written what I feel is an improved version of the Fraction class in Objective-C. As per the tips in this answer, the class ...
1
vote
1answer
103 views

Converting object oriented style code to functional in Scala

I came across Java like Scala code that I am trying to refactor to make it functional and immutable. The first obvious flaw is that it's violating thread safety by using mutable public class level ...
5
votes
2answers
3k views

Insert a character into a string

For practicing reasons I would like to write a method which inserts a character into a string. I would like to know: What is the best practice concerning placement of a comment within methods? For ...
6
votes
1answer
99 views

Allow changing the properties of a mutable controller in a thread safe way

I have a (control engineering) controller. These controllers usually need several parameters to do their thing, and in my application it is desirable that these parameters can be changed while the ...
5
votes
1answer
307 views

How is my implementation of an immutable stack?

Below is my implementation of an immutable stack class. The reverse function is trying to return a stack with all elements reversed. Is my implementation good? Maybe the reverse function can be ...
4
votes
1answer
258 views

Functional linked list

I'm looking for feedback in general: code correctness, best practices, design patterns; everything you think about this. Is it bad code? Where can it be improved? I've been implementing functional ...
1
vote
1answer
84 views

Removing redundancy from an immutable “rules class”

I am writing a board game program in Java. Slightly similar to chess or civilization in that each player has a set of units, and each unit has certain actions that it can take. The base ...
5
votes
1answer
305 views

Immutable C++ stack - thoughts and performance

What are your thoughts on the fallowing immutable stack implementation? It is implemented having as a basis a C# immutable stack (where garbage collector assistance does not impose using a reference ...
1
vote
2answers
138 views

Modify or not modify your objects when creating computing functions?

See the examples below: ...
6
votes
1answer
150 views

Circular dependencies between immutable objects; the Freeze Pattern

Generally, I structure small threadsafe immutable objects like this: ...
1
vote
2answers
349 views

Comments on my Java pattern for Mutable turned Immutable objects

Commenting omitted to give you the idea. I've been toying with this recently as a variant of the Builder pattern. I've recently fallen in love with immutable objects for the benefits they give in ...
1
vote
2answers
426 views
3
votes
2answers
522 views

Immutable pure data classes with public setters on properties

I'm putting together some classes as a model for some information (that I'm currently pulling from a website). The classes are implemented in C# - because in the current version of F# there are no ...