Home

Immutabilitet

Immutabilitet, the Danish term for immutability, is the property of an object whose state cannot be changed after creation. In programming, immutable values or data structures cannot be modified in place; any operation that would seem to modify them instead yields a new object with the updated state. This contrasts with mutable objects, which can be altered after creation.

Immutability is a central concept in functional programming and in many modern languages that favor predictable,

Practically, immutability supports safer concurrent execution, easier reasoning about code, and robust auditing. It underpins patterns

Trade-offs include potential increases in memory use and CPU time, since edits may require creating new objects.

side-effect-free
code.
It
enables
referential
transparency,
meaning
an
expression
can
be
replaced
by
its
value
without
changing
program
behavior.
Implementations
use
persistent
(or
structural-sharing)
data
structures,
copy-on-write
techniques,
and
controlled
mutation
through
new
instances
rather
than
in-place
edits.
Languages
such
as
Haskell,
Erlang,
and
Clojure
embrace
immutability
by
default
or
offer
immutable
collections;
other
languages
provide
explicit
immutable
types
or
modifiers
like
const
or
final.
such
as
event
sourcing
and
append-only
logs,
where
history
is
preserved
by
storing
immutable
records
of
changes.
In
databases
and
distributed
systems,
immutability
helps
ensure
consistency,
tamper-evidence,
and
reproducible
state
across
replicas.
The
cost
can
be
mitigated
with
sharing,
structural
sharing,
and
efficient
persistent
structures.
The
choice
between
mutable
and
immutable
design
depends
on
performance,
resource
constraints,
and
the
need
for
correctness
and
auditability.