-
Notifications
You must be signed in to change notification settings - Fork 39
Value
Values are timeless abstractions in the same sense that the number 2 is an abstraction that subsumes all particular pairs.
When we add 2 to 3 we don't mutate 3.
When we add 2 to 3 + i, we don't mutate the real part of 3 + i.
Treating an array of number as a value means that when we update the second element of the array [2, 3], we don't mutate the second element of the array.
An expression made of values can be understood by understanding its constituents. We can safely represent an expression made of values by its result.
A simple example: Each time we encounter 2 + 3, we can safely replace it by 5.
It is not meaningful to speak about this number 2 or that number 2. There is just 2.
It is not meaningful to speak about this "hello" string or that "hello" string. There is just "hello".
Values cannot be copied or shared. There is not such a thing as "copies" of a value.
When we store a value inside a program, we might decide for efficiency reason to share or to copy the storage of the value. But it has nothing to do with the semantics of the value.
Values cannot be created or destroyed.
When we write 2 + 3, it doesn't mean that 5 has been created and 2 and 3 have been destroyed.
- In all programming languages, numbers are treated as values.
- In most programming languages, strings are treated as values.
- In functional programming languages, data collections are treated as values.