What is a “mostly complete” (im)mutability approach for C#? [closed]
Would the better solution be to just use F# where you want true immutability?
Would the better solution be to just use F# where you want true immutability?
You may want to re-read The Rust Programming Language, specifically the sections on: mutability mutable references vectors We can also iterate over mutable references to each element in a mutable vector in order to make changes to all the elements. The for loop in Listing 8-9 will add 50 to each element. let mut v … Read more
User classes are considered mutable. Python doesn’t have (absolutely) private attributes, so you can always change a class by reaching into the internals. For using your class as a key in a dict or storing them in a set, you can define a .__hash__() method and a .__eq__() method, making a promise that your class … Read more
How are arrays, having O(1) time to access or modify an indexed element, implemented in Haskell They are implemented via primitive operations in the runtime system for memory reads and writes. The safety of the side effecting action of destructively writing to memory is ensured via the use of monads to linearize access to the … Read more
This is sort of a side note explanation on some of the details of volatile. Writing this here because it is too much for an comment. I want to give some examples which show how volatile affects visibility, and how that changed in jdk 1.5. Given the following example code: public class MyClass { private … Read more
The first way: def change(array): array.append(4) change(array) is the most idiomatic way to do it. Generally, in python, we expect a function to either mutate the arguments, or return something1. The reason for this is because if a function doesn’t return anything, then it makes it abundantly clear that the function must have had some … Read more
Yes, << mutates the same object, and + creates a new one. Demonstration: irb(main):011:0> str = “hello” => “hello” irb(main):012:0> str.object_id => 22269036 irb(main):013:0> str << ” world” => “hello world” irb(main):014:0> str.object_id => 22269036 irb(main):015:0> str = str + ” world” => “hello world world” irb(main):016:0> str.object_id => 21462360 irb(main):017:0>
It looks like a_list would still be initialized only once “initialization” is not something that happens to variables in Python, because variables in Python are just names. “initialization” only happens to objects, and it’s done via the class’ __init__ method. When you write a = 0, that is an assignment. That is saying “a shall … Read more
It’s just a missing case that will presumably eventually be filled in. There is no reason not to do it, and in certain cases it would be considerably faster than the immutable tree (since modifications require log(n) object creations with an immutable tree and only 1 with a mutable tree). Edit: and in fact it … Read more
I would declare a readonly NSArray in your header and override the getter for that array to return a copy of a private NSMutableArray declared in your implementation. Consider the following. Foo.h @interface Foo @property (nonatomic, retain, readonly) NSArray *array; @end Foo.m @interface Foo () @property (nonatomic, retain) NSMutableArray *mutableArray @end #pragma mark – @implementation … Read more