jargon

Comparison

Object equalityvsReference vs value semantics

Object equality

you put it in a set, put an identical one in, and the set had two of them.

The distinction between two references pointing at the same object and two objects being considered the same value. Getting it wrong is the standard source of duplicated set members, failed map lookups and tests that pass individually; getting it right means overriding equality and the hash together, and only ever on fields that do not change. Entities are compared by identity and value objects by value, which is the whole practical content of that distinction.

Full entry →

Reference vs value semantics

you passed it to a function, the function changed it, and your copy changed too — or it did not, and you had to know which.

Whether assigning or passing something shares one object or produces an independent copy. It decides whether aliasing is possible at all, and therefore whether defensive copying, immutability and thread-safety are concerns in a given piece of code. Most mainstream languages are reference-semantic for objects and value-semantic for primitives, which is exactly enough inconsistency to catch people out at a boundary.

Full entry →

Related comparisons