immutability Questions

6

Solved

I have a routine where I receive some data from an api. I'd like to store this data in an object, but after that i want to "lock" this object and not allow any change to the properties or their val...
Aquarium asked 20/10, 2017 at 16:20

13

Solved

In Ruby some methods have a question mark (?) that ask a question like include? that ask if the object in question is included, this then returns a true/false. But why do some methods have exclama...
Theophylline asked 4/3, 2009 at 20:2

19

Solved

I'm rebuilding an old Java project in Javascript, and realized that there's no good way to do enums in JS. The best I can come up with is: const Colors = { RED: Symbol("red"), BLUE: Symbol("bl...
Wigfall asked 9/6, 2017 at 1:19

7

Solved

I want to subclass dict in python such that all the dictionaries of the sub-class are immutable. I don't understand how does __hash__ affects the immutability, since in my understanding it just sig...
Wreckful asked 13/6, 2012 at 11:52

6

Solved

I want to have a function which returns an Array, but I want the returned Array to be readonly, so I should get a warning/error when I try to change its contents. function getList(): readonly numb...
Interlope asked 24/4, 2018 at 13:36

4

Solved

Is it possible to create a Pydantic field that does not have a default value and this value must be set on object instance creation and is immutable from then on? e.g. from pydantic import BaseMode...
Fabrienne asked 10/1, 2022 at 6:38

4

Solved

I have a struct which I put in a List<T>, I want to edit some value in that struct at a specific position. Is this at all possible without making a copy of the struct, editing the copy, and r...
Wageworker asked 21/11, 2012 at 1:4

7

Solved

If I want to represent my view controller's state as a single struct and then implement an undo mechanism, how would I change, say, one property on the struct and, at the same time, get a copy of t...
Fordo asked 12/7, 2016 at 14:9

4

Solved

I'm doing some distributed computing in which several machines communicate under the assumption that they all have identical versions of various classes. Thus, it seems to be good design to make th...
G asked 14/2, 2011 at 20:16

27

Solved

Although I have never needed this, it just struck me that making an immutable object in Python could be slightly tricky. You can't just override __setattr__, because then you can't even set attribu...
Christenachristendom asked 28/1, 2011 at 12:14

3

Solved

To illustrate the necessity of Rc<T>, the Book presents the following snippet (spoiler: it won't compile) to show that we cannot enable multiple ownership without Rc<T>. enum List { Co...
Retiarius asked 29/5, 2021 at 4:10

4

Solved

It is stated in the specifications and the requiremnets of the project, that Id of Product should not be changeable..it is of type Long Does it mean, it must be immutable? If yes, how to chec...
Engraving asked 15/9, 2019 at 13:24

1

Vue triggers component re-render by it's reactivity mechanism, so developers can mutate states directly. Vue will detect the state change and trigger component rerender. React triggers component ...
Lobbyism asked 11/9, 2018 at 15:59

8

Solved

Is there an easy way to make an instance immutable? Let's do an example, I have a class holding a lots of data fields (only data, no behavior): class MyObject { // lots of fields painful to init...
Masked asked 29/9, 2014 at 17:35

3

Solved

Question ahead: why does in Java the call coll.contains(null) fail for ImmutableCollections? I know, that immutable collections cannot contain null-elements, and I do not want to discuss whether th...
Punk asked 5/2, 2021 at 15:43

3

Solved

So I'm exploring Rust, and I have read about technical differences between constants and immutable variables. But it seems like immutable variables can do all things that constants can. Then what i...
Lornalorne asked 18/1, 2022 at 17:55

4

Solved

I have this piece of code that loads Properties from a file: class Config { val properties: Properties = { val p = new Properties() p.load(Thread.currentThread().getContextClassLoader.getResou...
Spoilsman asked 28/1, 2013 at 17:50

3

Solved

Note this is similar to How to get @property methods in asdict?. I have a (frozen) nested data structure like the following. A few properties that are (purely) dependent on the fields are defined. ...

4

Solved

I've been using Python for some time already and today while reading the following code snippet: >>> a = (1,2) >>> a += (3,4) >>> a (1, 2, 3, 4) I asked myself a quest...
Kozak asked 25/9, 2013 at 21:44

2

I have an object (numpy.ndarray, for example), that should be passed as an argument to several functions. In C++ in such cases I declared such arguments as const, in order to show, that they must n...
Envisage asked 20/4, 2014 at 10:44

3

Solved

Before concretizing my question, let me provide some background: My main programming languages are C++ and Java. When working with C++ I find it important to apply const correctness, that is declar...
Amplifier asked 7/5, 2016 at 11:9

12

Solved

Is there anything in Python that works like the final keyword in Java - i.e., to disallow assigning to a specific attribute of the instances of a class, after those instances have been created? I c...
Billhook asked 29/4, 2009 at 14:21

10

Solved

I've recently been learning about functional programming (specifically Haskell, but I've gone through tutorials on Lisp and Erlang as well). While I found the concepts very enlightening, I still do...
Politicize asked 10/5, 2009 at 2:9

11

Solved

I have got one class with various member variables. There is a constructor and there are getter-methods, but no setter-methods. In fact, this object should be immutable. public class Example { pr...
Aspirator asked 26/5, 2011 at 10:39

2

Solved

I was taught that structs should almost always be immutable, so this unusual behaviour of record classes vs. record structs threw me off guard. Using a record class... record class Person(string Fi...
Cypriot asked 18/7, 2022 at 18:22

© 2022 - 2024 — McMap. All rights reserved.