immutable

What's the best name for a non-mutating "add" method on an immutable collection?

Sorry for the waffly title - if I could come up with a concise title, I wouldn't have to ask the question. Suppose I have an immutable list type. It has an operation Foo(x) which returns a new immutable list with the specified argument as an extra element at the end. So to build up a list of strings with values "Hello", "immutable", "wo...

Passing and storing pointers to immutable types and strings in C#

Is there a way to store a pointer to immutable types like strings in C#? How can execute: Instance1.SomeFunction(out MyString); ,and store a pointer to MyString inside of Instance1? ...

Pure functions in C#

I know C# is getting a lot of parallel programming support, but AFAIK there is still no constructs for side-effects verification, right? I assume it's more tricky now that C# is already laid out. But are there plans to get this in? Or is F# the only .NET language that has constructs for side-effects verification? ...

Are some data structures more suitable for functional programming than others?

In Real World Haskell, there is a section titled "Life without arrays or hash tables" where the authors suggest that list and trees are preferred in functional programming, whereas an array or a hash table might be used instead in an imperative program. This makes sense, since it's much easier to reuse part of an (immutable) list or tr...

Immutability of structs

I read it in lots of places including here that it's better to make structs as immutable. What's the reason behind this? I see lots of Microsoft-created structs that are mutable, like the ones in xna. Probably there are many more in the BCL. What are the pros and cons of not following this guideline? ...

What is immutability and why should I worry about it?

I've read a couple of articles on immutability but still don't follow the concept very well. I made a thread on here recently which mentioned immutability, but as this is a topic in itself, I am making a dedicated thread now. I mentioned in the past thread that I thought immutability is the process of making an object read only and giv...

How to pass references by value in C++?

I'm trying to create am immutable type (class) in C++, I made it so that all methods "aka member functions" don't modify the object and return a new instance instead. I'm running across a bunch of issues, but they all revolve around the reference types in C++. One example is when passing parameters of the same class type by reference:...

Is a lock required with a lazy initialization on a deeply immutable type?

If I have a deeply immutable type (all members are readonly and if they are reference type members, then they also refer to objects that are deeply immutable). I would like to implement a lazy initialized property on the type, like this: private ReadOnlyCollection<SomeImmutableType> m_PropName = null; public ReadOnlyCollection<SomeImmu...

How do I make a Java class immutable in Clojure?

I'd like to wrap java's PriorityQueue class in clojure for use in another part of my program. What I'm trying to figure out is if there is any way to do this in a lispy manner and make the priority queue immutable. Are there any good ways to do this, or am I just going to be better off using the PriorityQueue as a mutable data structur...

Conventions for immutable objects

When you design immutable classes, do you prefer: Layer.ColorCorrect ( layer ) or layer.ColorCorrect ( ) To me #1 seems more intuitive, instead of #2, which looks like it modifies the object that's referenced, since it's an instance method, it might as well change the internals, right? ...

Mutable or immutable closures

In an imperative, object orients language, would make more sense to have mutable or immutable closures? For example: int i=5; function() f={print(i);}; f(); i=6; f(); If the closure is mutable, this would print: 5 6 If it is immutable, it would print: 5 5 I realize that even with immutable closures, you could still do this: cl...

How deep would you expect the immutability of an immutable list to be?

If you have an immutable list, you expect it to always return a reference to the same object when you ask for, say list.get(0) My question is, would you expect to be able to mutate the object and have the mutation reflected next time you get it from the list? ...

Persistent data structures in Java

Does anyone know a library or some at least some research on creating and using persistent data structures in Java? I don't refer to persistence as long term storage but persistence in terms of immutability (see Wikipedia entry). I'm currently exploring different ways to model an api for persistent structures. Using builders seems to be...

Immutability and thread safety in Python

I'm cleaning some of the Python code I wrote when I was...not as knowledgeable. Primarily I am killing some of the complexity that stemmed from an incomplete understanding of threading in Python. I need to make a list of items thread-safe, and I'd like to do it via immutable lists, instead of the usual locking approach. I know that immut...

Repository and Immutable objects?

I may be doomed by an impedence mismatch, but I'm trying to reconcile examples I've seen for IRepository and immutable objects. I'm working on a cataloging application where hundrds of web requests operate on a 'working set' of products - a subset of the whole catalog tends to be in play at any given time. At the same time, our data te...

Downsides to immutable objects in Java?

The advantages of immutable objects in Java seem clear: consistent state automatic thread safety simplicity You can favour immutability by using private final fields and constructor injection. But, what are the downsides to favouring immutable objects in Java? i.e. incompatibility with ORM or web presentation tools? Inflexible de...

Creating immutable objects from javabean

Hi All, I am involved in this project where we are building on good bit of legacy code. I have a particular situation about one big java bean object which has to be transferred over wire. So my first thought was to make it immutable and serializable to do the trick .At this point I am faced with a few difficult choices :- 1> Ideally ...

Are Delphi strings immutable?

As far as I know, strings are immutable in Delphi. I kind of understand that means if you do: string1 := 'Hello'; string1 := string1 + " World"; first string is destroyed and you get a reference to a new string "Hello World". But what happens if you have the same string in different places around your code? I have a string hash assi...

Will System.Numerics.BigInteger be immutable? Should it be?

The .net framework 4 is apparently going to include a BigInteger class. However, I can't seem to find out whether or not it will be immutable. I also can't seem to decide whether or not that would be a good thing. Immutability has a ton of benefits, especially for something as "value-like" as a big-int. On the other hand, the basic oper...

How to bestow string-ness on my class?

I want a string with one additional attribute, let's say whether to print it in red or green. Subclassing(str) does not work, as it is immutable. I see the value, but it can be annoying. Can multiple inheritence help? I never used that. Inheriting only object and using self.value=str means I have to implement all string-ness messages ...