DELAPARRA
Index
Color
NL
Category: Programming paradigms

Immutability

Explained by Updated

What is Immutability?

Immutability: Data is never modified after creation. Instead of changing an existing array, you return a new one. This eliminates a whole class of bugs caused by unexpected mutation. Immutability means data is not changed after it is created. Instead of modifying an object or array, you create a new version with the change applied.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Immutability

How is Immutability used in practice?

This removes a whole class of bugs. When an object cannot change, you never need to worry that some other part of the code modified it behind your back. That makes code easier to reason about, especially with caching, concurrency and long-running processes.

What should you keep in mind with Immutability?

Modern PHP supports it with readonly properties and classes, and Carbon offers CarbonImmutable for dates, where $date->addDay() returns a new date instead of changing the original. In JavaScript, the spread syntax and libraries like Immer help. Immutable value objects, such as money amounts, addresses or date ranges, are a good place to start using the idea.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with I

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.