Value semantics

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]

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.



This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.