I want to have an Object with immutable fields in Objective-C.
In C#, I would use Properties with private setters and a big constructor.
What would I use in Objective-C?
Using @property doesn't seem to allow me to declare the setter as private.
Using
initWithData: (NSString*) something createDate: (NSDate*) date userID: (long) ui...
I am trying to convert a mutable class to an Immutable class following the advices given in
Effective Java Item 15 (Minimize Mutability). Can anybody tell me whether the class I created is
fully immutable or not?
Mutable Class
public class Record {
public int sequenceNumber;
public String id;
public List<Field> fields;
...
Hi
I understand that val keyword determines the underlying variable is a Immutable type (Cannot be reassigned later time). Now i come across a paragraph in programming in scala (Chapter 3, Next steps in scala - parameterize arrays with types), it states
val greetStrings: Array[String] = new Array[String](3)
greetStrings(0) = "Hello"
gr...
I want to get an array of bytes (Array[Byte]) from somewhere (read from file, from socket, etc) and then provide a efficient way to pull bits out of it (e.g. provide a function to extract a 32-bit integer from offset N in array). I would then like to wrap the byte array (hiding it) providing functions to pull bits out from the array (pro...
If I would like to carry out multiple string replacements, what is the most efficient way to carry this out?
An example of the kind of situation I have encountered in my travels is as follows:
>>> strings = ['a', 'list', 'of', 'strings']
>>> [s.replace('a', '')...replace('u', '') for s in strings if len(s) > 2]
['a', 'lst', 'of', 'st...
String s = ...;
s = s.substring(1);
Is this possible? I thought you can't change a String object in Java.
...
Once I studied about the advantage of a string be immutable because of something to improve performace in memory..
Can anybody explain me this please? I can't find in Internet.
Thanks a lot.
...
I have below a description of a data structure I need and I want to implement it using immutable data structures. I'm trying to determine... is there an existing data structure out there that will support what I'm trying to do here or do I need to create one--and if I need to create it, what would be a good place to start (building block...
I know I can remove the last element from a set:
s.Remove(s.MaximumElement)
But if I want to remove the n maximum elements... do I just execute the above n times, or is there a faster way to do that?
To be clear, this is an obvious solution:
let rec removeLastN (s : Set<'a>, num : int) : Set<'a> =
match num with
| 0 -> s
...
It certainly does not break from the standard practice of the .NET framework. When I see a a + b I always assume something new will be created.
static void Main(string[] args)
{
var list = BuildList(ImmutableList<int>.Empty);
var sum = (list + 500).Sum();
Console.WriteLine(sum);
Console.ReadLine();
}
static ImmutableLis...
In Scala I would like to be able to write
val petMap = ImmutableMultiMap(Alice->Cat, Bob->Dog, Alice->Hamster)
The underlying Map[Owner,Set[Pet]] should have both Map and Set immutable. Here's a first draft for ImmutibleMultiMap with companion object:
import collection.{mutable,immutable}
class ImmutableMultiMap[K,V] extends immutab...
I am writing a function that returns a reference to an object of some encapsulated data structure and I want nobody to be able to change the object using that reference, is it possible to do this in c#?
...
I've been reading a bit about immutable structures such as string. Simply put, they don't change state once they've been created (so for instance asking for a substring gives you a new string).
Now, I was wondering whether the CLR "knows" that a certain type is immutable, and uses this fact to do something clever at runtime, or is immut...
Intro
Currently I have something of the form:
Tetris class ---> FallingPiece class ----> Piece class
A Piece can be a Square, a T, etc. It has info about its shape and the shapes of its rotations, its size, etc.
The FallingPiece class basically contains an attribute with a reference to a Piece (the currently falling piece in the Te...
Some background: I am writing a generic high-level to low-level compiler. On the high-level side, it understands classes, methods, fields, virtual method calls, etc. and on the low-level side, it understands functions, structures, arrays, etc. Front-ends translate compiled forms of languages like Java (the main focus) and C# into my IR...
Hi all,
I would like to construct my domain model using immutable objects only. But I also want to use traits with val fields and move some functionality to traits. Please look at the following example:
trait Versionable {
val version = 0
def incrementVersion = copy(version=version+1)
}
Unfortunatelly such code doesn't work - copy ...
It seems to me there is an extreme lack of safe, immutable collection types for .NET, in particular BCL but I've not seen much work done outside either. Do anyone have any pointers to a (preferably) production quality, fast, immutable collections library for .NET. A fast list type is essential. I'm not yet prepared to switch to F#.
...
I have implemented a few Java applications now, only desktop applications so far. I prefer to use immutable objects for passing the data around in the application instead of using objects with mutators (setters and getters), also called JavaBeans.
But in the Java world, it seems to be much more common to use JavaBeans, and I can't under...
I don't know if there is a specific name for this, but I am designing an application backed by a database in which rows need to be immutable (not sure if that term applies here, but it is the closest to describing what I need). That is, instead of changing the data stored in a row, a new row would be inserted with the same id but a diff...
According to MSDN, System.Int32 is immutable, and its members always return new instances.
Some common code, like for loop, requires ++ operation quite often.
Does increment always create new instances and discard the old ones? As far as I can see, this approach will severely affect the performance. And I wonder how Microsoft implements ...