mutability

returning IList<T> vs Array in C#?

I was recently asking someone why he preferred to return a strongly-typed array over an IList. I had always thought that programming against an interface was the most flexible and best way program when faced with a project having a long life. So it struck me as odd when he replied: We typically prefer immutable types over mutable o...

Scala: Mutable vs. Immutable Object Performance - OutOfMemoryError

I wanted to compare the performance characteristics of immutable.Map and mutable.Map in Scala for a similar operation (namely, merging many maps into a single one. See this question). I have what appear to be similar implementations for both mutable and immutable maps (see below). As a test, I generated a List containing 1,000,000 s...

Copy & mutableCopy?

What is the difference between the "copy" & "mutableCopy"? EDIT_001: My original post was a bit of a mess, partly due to a lack of understanding and partly due to a bit of pilot error on my part. Here is my attempt to better explain how "copy" & "mutableCopy" work. // ** NSArray ** NSArray *myArray_imu = [NSArray arrayWithObjects:@...

Does "Value Restriction" practically mean that there is no higher order functional programming?

Does "Value Restriction" practically mean that there is no higher order functional programming? I have a problem that each time I try to do a bit of HOP I get caught by a VR error. Example: let simple (s:string)= fun rq->1 let oops= simple "" type 'a SimpleType= F of (int ->'a-> 'a) let get a = F(fun req -> id) let oops2= get "" ...

NSMutableArray can't be added to

I've had this sort of problem before, and it didn't get a satisfactory answer. I have a viewcontroller with a property called "counties" that is an NSMutableArray. I'm going to drill down a navigation screen to a view that is about selecting the counties for a geographical search. So the search page drills down to the "select counties"...

Mutability design patterns in Objective C and C++

Having recently done some development for iPhone, I've come to notice an interesting design pattern used a lot in the iPhone SDK, regarding object mutability. It seems the typical approach there is to define an immutable class NSFoo, and then derive from it a mutable descendant NSMutableFoo. Generally, the NSFoo class defines data membe...

Mixed vs. separated class mutability

In a partially mutable class, is it better to mix mutable fields with its immutable ones, or create a new class (or classes) that encapsulate them? Here's an example in C# of what I'm talking about: interface IBedroom { int Volume { get; } string Color { get; } void Paint(string newColor); } Here's an implementation wit...

Mutable vs Ref variables in terms of capture

My superficial understanding of variables in f# suggests that declaring a variable to be 'mutable' and using a 'ref' variable essentially both do the same thing. They are both different ways to address the same underlying issue - a limited and structured allowance of mutability in a functional language without having to resort to the IO...