Value semantics

Last updated

In computer science, having value semantics (also value-type semantics or copy-by-value semantics) means for an object that only its value counts, not its identity. [1] [2] Immutable objects have value semantics trivially, [3] and in the presence of mutation, an object with value semantics can only be uniquely-referenced at any point in a program.

The concepts that are used to explain this concept are extensionality, definiteness, substitutivity of identity, unfoldability, and referential transparency. [4]

Related Research Articles

E-Prime refers to a version of the English language that excludes all forms of the verb to be, including all conjugations, contractions and archaic forms.

In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map values to other values, rather than a sequence of imperative statements which update the running state of the program.

Referential transparency and referential opacity are properties of parts of computer programs. An expression is called referentially transparent if it can be replaced with its corresponding value without changing the program's behavior. This requires that the expression be pure, that is to say the expression value must be the same for the same inputs and its evaluation must have no side effects. An expression that is not referentially transparent is called referentially opaque.

A noun is a word that functions as the name of a specific object or set of objects, such as living creatures, places, actions, qualities, states of existence, or ideas. However, noun is not a semantic category, so it cannot be characterized in terms of its meaning. Thus, actions and states of existence can also be expressed by verbs, qualities by adjectives, and places by adverbs. Linguistically, a noun is a member of a large, open part of speech whose members can occur as the main word in the subject of a clause, the object of a verb, or the object of a preposition. Many different types of nouns exist, including proper and common nouns, collective nouns, mass nouns, and so forth.

In object-oriented and functional programming, an immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created. In some cases, an object is considered immutable even if some internally used attributes change, but the object's state appears unchanging from an external point of view. For example, an object that uses memoization to cache the results of expensive computations could still be considered an immutable object.

In object-oriented programming, object copying is creating a copy of an existing object, a unit of data in object-oriented programming. The resulting object is called an object copy or simply copy of the original object. Copying is basic but has subtleties and can have significant overhead. There are several ways to copy an object, most commonly by a copy constructor or cloning. Copying is done mostly so the copy can be modified or moved, or the current value preserved. If either of these is unneeded, a reference to the original data is sufficient and more efficient, as no copying occurs.

Substitutability is a principle in object-oriented programming stating that, in a computer program, if S is a subtype of T, then objects of type T may be replaced with objects of type S without altering any of the desirable properties of the program. More formally, the Liskov substitution principle (LSP) is a particular definition of a subtyping relation, called (strong) behavioral subtyping, that was initially introduced by Barbara Liskov in a 1988 conference keynote address titled Data abstraction and hierarchy. It is a semantic rather than merely syntactic relation, because it intends to guarantee semantic interoperability of types in a hierarchy, object types in particular. Barbara Liskov and Jeannette Wing described the principle succinctly in a 1994 paper as follows:

Subtype Requirement: Let be a property provable about objects of type T. Then should be true for objects of type S where S is a subtype of T.

In computer programming, an assignment statement sets and/or re-sets the value stored in the storage location(s) denoted by a variable name; in other words, it copies a value into the variable. In most imperative programming languages, the assignment statement is a fundamental construct.

Intuitionistic type theory is a type theory and an alternative foundation of mathematics. Intuitionistic type theory was created by Per Martin-Löf, a Swedish mathematician and philosopher, who first published it in 1972. There are multiple versions of the type theory: Martin-Löf proposed both intensional and extensional variants of the theory and early impredicative versions, shown to be inconsistent by Girard's paradox, gave way to predicative versions. However, all versions keep the core design of constructive logic using dependent types.

In computing, a persistent data structure or not ephemeral data structure is a data structure that always preserves the previous version of itself when it is modified. Such data structures are effectively immutable, as their operations do not (visibly) update the structure in-place, but instead always yield a new updated structure. The term was introduced in Driscoll, Sarnak, Sleator, and Tarjans' 1986 article.

In class-based object-oriented programming, a constructor is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.

David Benjamin Kaplan is an American philosopher. He is the Hans Reichenbach Professor of Scientific Philosophy at the UCLA Department of Philosophy. His philosophical work focuses on the philosophy of language, logic, metaphysics, epistemology and the philosophy of Frege and Russell. He is best known for his work on demonstratives, propositions, and reference in intensional contexts. He was elected a Fellow of the American Academy of Arts & Sciences in 1983 and a Corresponding Fellow of the British Academy in 2007.

In the C, C++, D, JavaScript and Julia programming languages, const is a type qualifier: a keyword applied to a data type that indicates that the data is read only. While this can be used to declare constants, const in the C family of languages differs from similar constructs in other languages in being part of the type, and thus has complicated behavior when combined with pointers, references, composite data types, and type-checking.

C Sharp (programming language) Multi-paradigm (object-oriented) programming language

C# is a general-purpose, multi-paradigm programming language. C# encompasses static typing, strong typing, lexically scoped, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines.

In the Java programming language, the final keyword is used in several contexts to define an entity that can only be assigned once.

In a programming language, an evaluation strategy is a set of rules for evaluating expressions. The term is often used to refer to the more specific notion of a parameter-passing strategy that defines whether to evaluate the parameters of a function call, and if so in what order and the kind of value that is passed to the function for each parameter. The notion of reduction strategy is distinct, although some authors conflate the two terms and the definition of each term is not widely agreed upon.

An opaque context or referentially opaque context is a linguistic context in which it is not always possible to substitute "co-referential" expressions without altering the truth of sentences. The expressions involved are usually grammatically singular terms. So, substitution of co-referential expressions into an opaque context does not always preserve truth. For example, "Lois believes x is a hero" is an opaque context because "Lois believes Superman is a hero" is true while "Lois believes Clark Kent is a hero" is false, even though 'Superman' and 'Clark Kent' are co-referential expressions.

In computer science, a value object is a small object that represents a simple entity whose equality is not based on identity: i.e. two value objects are equal when they have the same value, not necessarily being the same object.

In computer programming, a constant is a value that should not be altered by the program during normal execution, i.e., the value is constant. When associated with an identifier, a constant is said to be "named," although the terms "constant" and "named constant" are often used interchangeably. This is contrasted with a variable, which is an identifier with a value that can be changed during normal execution, i.e., the value is variable. Constants are useful for both programmers and compilers: For programmers they are a form of self-documenting code and allow reasoning about correctness, while for compilers they allow compile-time and run-time checks that verify that constancy assumptions are not violated, and allow or simplify some compiler optimizations.

In the C, C++, and D programming languages, a type qualifier is a keyword that is applied to a type, resulting in a qualified type. For example, const int is a qualified type representing a constant integer, while int is the corresponding unqualified type, simply an integer. In D these are known as type constructors, by analogy with constructors in object-oriented programming.

References

  1. "Some Basic QUESTIONS". velocity reviews. Retrieved 2011-06-17. The important consideration for value semantics is that only the value of an object is significant, not its identity. So you can copy it (copy constructor or assignment) as much as you like, and any copy can be used in place of the original with no change.
  2. Daniel Elstner. "Re: extending Gdk::Region". GTK & GNOME Mailing Lists. Retrieved 2011-06-17. What are value semantics? [...] It's an ad hoc shorthand for "value-type semantics", or "copy-by-value semantics".
  3. "Some Basic QUESTIONS". velocity reviews. Retrieved 2011-06-17. An object represents an immutable value (vs. an object represents a system with a mutable state.) [...] Not necessarily, at least not in C++. I do like the idea that an object with value semantics can only be modified by the assignment operators, but this is far from the general case---std::string, for example, clearly has value semantics, despite a large number of mutator functions. (One can argue that this is a design error, but if so, it's still one we have to live with.)
  4. "Some Basic QUESTIONS". velocity reviews. The important consideration for value semantics is that only the value of an object is significant, not its identity. So you can copy it (copy constructor or assignment) as much as you like, [...] One can eventually identify five different concepts that can be used to explain this notion in a more precise manner, these are: extensionality, definiteness, substitutivity of identity, unfoldability, and referential transparency.