Skip to content

Value vs. Reference Semantics

Assignment can either copy the data (value semantics - independence) or share access to the same data (reference semantics - aliasing). This choice has profound implications for reasoning about program behavior.

Tension Addressed

Value vs. Reference Semantics

Recognizable As

Primitives vs. objects behaving differently on assignment; deep copy vs. shallow copy debates; "pass by value" vs. "pass by reference"; defensive copying; immutable objects as reference-semantic but behaviorally value-semantic

Canonical Sources

Liskov & Guttag, Program Development in Java (2001); MacLennan, "Values and Objects in Programming Languages" (1982)

Transfers To

Distributed systems (data replication vs. single source of truth), UI state management (copied state vs. shared state), any domain with multiple consumers of the same data

This tension cannot be eliminated - only managed. Value semantics provides isolation (changes don't affect other copies) at the cost of memory and synchronization. Reference semantics provides efficiency and shared state at the cost of aliasing hazards. Immutability offers a third option: reference semantics with value-semantic behavior.