I have a special kind of variables, the value of which can be assigned only once. When assigning an object, a link to it is assigned.
But at the same time the state of the object can be changed. Constant object is suitable or not?
I have a special kind of variables, the value of which can be assigned only once. When assigning an object, a link to it is assigned.
But at the same time the state of the object can be changed. Constant object is suitable or not?
In the theory of programming languages, this is called name binding , in other words, a comparison of a specific object with a name, as opposed to a variable, which is a slot in memory, where you can put the value of an object (if it is, say, a number), or a link to it .
If you just decided to create a container class that can be initialized with a certain value, but you cannot assign another, and decide how to name it, then you can use the term "cell" ( cell ), as is done in the Scala language:
scala> val container = new Cell(256) container: Cell[Int] = Cell(256) scala> container.elem res1: Int = 256 scala> container.elem = 257 <console>:6: error: reassignment to val container.elem = 257 ^
From the example it can be seen that the Cell container contains some element (elem), but it cannot be changed. At the same time, if, for example, an array is “put” while creating in Cell, then the elements of this array can legitimately be changed. You can also use the more colloquial name ImmutableCell or PersistentCell .
In the end, you can, without further ado, simply use the canonical term value , as opposed to variable. Scala authors do this (note the keywords: val (value) and var (variable)):
scala> val x = 10 x: Int = 10 scala> var y = 10 y: Int = 10 scala> y = 20 y: Int = 20 scala> x = 20 <console>:6: error: reassignment to val x = 20 ^
I would call immutable reference .
In my opinion, a very suitable term.
At least, this is a common terminology. It is quite natural and generally accepted that when they talk about const
(for example, a link or a list), the state of internal objects cannot be changed, and if the collection is immutable
, then it does not follow that the objects it contains are also immutable
.
PS Oh, carefully read the answer, which is the longest. There, too, at the end offer immutable
... In my opinion, an excellent and reasonable option.
I would call ConstReference, once the link.
And what is the area? What programming language? For example, in C ++ Const Reference will mean the inability to change the object:
const Object& obj_ref = obj;
so we say that obj_ref is a link to obj, but this link will not allow you to change obj.
If it is just a Reference, it will be assumed that the link has been assigned once, at the very beginning, but the object to which the link is going can be changed.
So in C ++ terms, just Reference.
Source: https://ru.stackoverflow.com/questions/9659/
All Articles