-
Notifications
You must be signed in to change notification settings - Fork 39
Identity
An identity is a stable logical entity that humans or programs associate with a series of attributes attributes over time. An identity represents a thread of continuity, though its attributes may change.
At a given point in time, the state of an identity is the value of its attributes.
Most programs deal with identity. We might even claim that:
Programming is identity-oriented mathematics
At a given point in time, the state of an identity is the value of its attributes.
Changing the state of an identity means changing the value of one or more of its attributes.
This is crucial to know whether an identity is shared or not. This is because a change made to the identity by one sharer will be visible to the other sharer.
An identity might be shared by:
- Functions in the same thread
- Threads in the same process
- Processes in the same machine
- Machines in the same cluster
- Different Clusters
Two identities might have the exact same attribute values and be different.
A single identity might have different attribute values at two different points in time.
Compare with Ship of Theseus.
In traditional OOP (e.g. Java, C#, C++) , we usually represent an identity with an object.
The problem with this approach is that we don't have access to the state of the object (the aggregated values of all its attributes) outside the context of the object. We can only access an attribute of the object (via member fields).
In Clojure, we usually represent an identity with an atom.
(def john (atom nil))
(def john-state-on-march-2021
{:age 42
:firstName "John"
:lastName "Doe"})
(reset! john john-state-on-march-2021)Let's describe exactly what happens in this code snippet in terms of name, identity, state and value:
-
johnis a name that refers to an identity - The identity is represented as an atom
- The map with the fields
age=42,firstName="John"andlastName="Doe"is a value - After calling
(reset! john ...), the state of the identity referred by the namejohnis the map with the fieldsage=42,firstName="John"andlastName="Doe".