Home

Immutability

Immutability is the property of an object or value whose state cannot be modified after it is created. In computing, immutable data remain constant, and any operation that would alter the value yields a new object with the desired changes. By contrast, mutable objects allow in-place modification of their contents.

In many programming languages, strings are immutable, meaning that applying operations like concatenation produces a new

Benefits of immutability include easier reasoning about program behavior, because values do not change unexpectedly; improved

However, immutability can introduce memory and performance trade-offs, especially when large data structures require many small

Immutability has practical use in user interfaces, state management, and functional programming. In data storage, append-only

string
rather
than
altering
the
original.
Some
languages
emphasize
immutability
by
default
(functional
languages
like
Haskell,
OCaml,
and
Clojure),
while
others
permit
both
mutable
and
immutable
data,
with
the
programmer
controlling
mutability
through
types,
conventions,
or
language
features.
thread
safety,
since
immutable
data
can
be
shared
across
threads
without
synchronization;
and
enable
optimizations
such
as
memoization
and
efficient
structural
sharing
in
persistent
data
structures.
changes.
Techniques
to
mitigate
this
include
persistent
or
structural
sharing,
copy-on-write
semantics,
and
returning
modified
copies
instead
of
mutating
originals.
Languages
may
also
offer
utilities
to
freeze
objects
or
to
enforce
immutability
at
compile
time.
logs
and
event
sourcing
rely
on
immutable
records;
blockchain
technologies
extend
the
concept
to
distributed
ledgers.
In
API
design,
immutable
data
transfer
objects
help
ensure
data
integrity
across
boundaries.