Home

Mutable

Mutable describes an object, data value, or variable that can be changed after it is created. In programming, mutability is the property that allows in-place updates, as opposed to immutability, where values cannot be altered once created.

Mutable state can simplify algorithms that require updates but introduces potential side effects and bugs. In

Common languages treat mutability differently. Python exposes mutability through built-in containers such as lists, dicts, and

Design choices about mutability affect memory use, performance, and reasoning about code. Mutable structures can support

See also immutability, const-correctness, and mutability in programming languages.

concurrent
or
parallel
contexts,
shared
mutable
state
requires
synchronization
to
prevent
data
races.
Immutable
values,
by
contrast,
are
inherently
thread-safe
and
easier
to
reason
about.
sets,
which
can
be
modified
after
creation,
while
strings
and
tuples
are
immutable.
Java
distinguishes
mutable
and
immutable
types:
strings
are
immutable,
whereas
arrays
and
most
user-defined
objects
are
mutable;
a
StringBuilder
offers
a
mutable
alternative
for
building
strings.
C++
provides
a
mutable
keyword
that
allows
a
class
member
to
be
modified
even
in
a
const
object,
reflecting
a
fine-grained
approach
to
mutability;
otherwise,
objects
are
mutable
by
default
unless
declared
const.
JavaScript
treats
objects
and
arrays
as
mutable;
primitive
values
like
numbers
and
strings
are
immutable.
Rust
uses
explicit
mutability
at
the
binding
level;
variables
are
immutable
by
default,
with
mut
enabling
changes,
and
more
complex
forms
of
interior
mutability
exist
via
Cell
or
RefCell.
in-place
updates
and
reduce
allocations,
but
require
careful
synchronization
and
debugging.
Immutable
structures
simplify
reasoning,
enable
safer
parallelism,
and
facilitate
certain
optimizations
such
as
caching
or
persistent
data
structures.