Skip to content
Skills Library
Programming · Building & coding

immutability-defaults

/immutability-defaults

Make immutability the default so aliasing bugs turn into compile errors or no-ops instead of action at a distance. Use when designing data structures, state updates, or any value shared across threads or call sites.

Repository
AI-SKILLS ↗
Licence
MIT
Last repository change
05.09.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 05.09.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Make immutability the default so aliasing bugs turn into compile errors or no-ops instead of action at a distance. Use when designing data structures, state updates, or any value shared across threads or call sites.

Original author description

Make immutability the default so aliasing bugs turn into compile errors or no-ops instead of action at a distance. Use when designing data structures, state updates, or any value shared across threads or call sites.

How it works

  1. Method
  2. Litmus tests
  3. Boundaries
Original SKILL.md headings · 53 lines, 409 words
SKILL.md preview
---
name: immutability-defaults
description: Make immutability the default so aliasing bugs turn into compile errors or no-ops instead of action at a distance. Use when designing data structures, state updates, or any value shared across threads or call sites.
---

# Immutability defaults

Shared mutable state is where bugs go to hide: a value changes under code
that assumed it was stable, and nothing in the type or the call site warned
you. Making immutability the default converts a whole class of aliasing
bugs into compile errors, and makes the ones that remain cheap to reason
about because a value you hold cannot change beneath you.

## Method

1. **Default every field to read-only.** Use `final` in Java, `val` in
   Kotlin, `readonly` in TypeScript, `const` bindings in JS, and
   `@dataclass(frozen=True)` in Python. Reach for a mutable field only when
   a profiler or a real hot loop demands it, and write the comment saying
   why.
2. **Copy on write, return the new value.** Instead of `list.sort()` in
   place, return a sorted copy; instead of mutating an argument, build and
   return a fresh object. Every caller keeps its original, so no distant
   reader breaks when you reorder or drop an element.
3. **Freeze at the boundary.** Data crossing into your module gets
   `Object.freeze`, `tuple(...)`, or a defensive copy, so a caller's later
   mutation cannot reach into your state. This is cheapest exactly where
   untrusted data first arrives.
4. **Prefer persistent structures over deep copies for large data.** Immer,
   Immutable.js, or pyrsistent share the unchanged structure and copy only
   the changed path, so a one-element update on a 10k map costs one small
   allocation, not 10k.
5. **Model updates as transformations.** A reducer that takes state and an
   event and returns new state is testable and replayable; an object that
   mutates itself in place is neither. Redux and event sourcing both stand
   on this shape.
6. **Watch the aliasing traps:** a default mutable argument
   (`def f(x=[])`), a getter that hands back the internal list, two names
   bound to one array. Each lets an edit in one place surface as a failure
   somewhere unrelated.

## Litmus tests

- Can two threads read this object with no lock and no surprise?
- If a caller holds a reference you returned, can their later edit change
  your state?
- Does any method named `copy` actually share the same underlying array or
  map?

## Boundaries

Hot paths with measured allocation pressure and large numeric buffers
(NumPy arrays, audio frames) are the honest exceptions: mutate them
locally, keep them un-shared, and document the ownership. Language idiom
wins too: fighting Go's value semantics or Rust's borrow checker to force a
foreign style costs more than the immutability buys.

Versions

The database has no other skills named immutability-defaults.

Database snapshot: 13.11.2026 · package version 0440f9550f01 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 90js-immutability
    Work with immutable data in JavaScript through structural updates, readonly types, and freeze where it earns its cost. Use when managing shared or reactive state, or debugging bugs from unexpected mutation.
  • 100clojure-lisp-immutability
    Use this skill when building concurrent, functional data-transformation pipelines in Clojure utilizing persistent immutability and atoms.
  • 100standards
    Cross-project coding standards. Triggers on /codeforge:review or new module setup. Naming, typing, immutability, KISS/DRY/YAGNI, error handling, observability.
  • 100coding-standards
    Baseline cross-project coding conventions for naming, readability, immutability, and code-quality review. Use detailed frontend or backend skills for framework-specific patterns. Use when reviewing code quality or naming with no framework-specific skill that applies.
  • 100functional
    Functional programming patterns with immutable data. Use when writing logic, data transformations, or encountering mutation bugs — including any feature request that builds, merges, filters, sorts, prices or otherwise reshapes records, lists, carts, orders or invoices, even when…
  • 100swift-best-practices
    Apply Guard, Value Types, Immutability, and Naming conventions in Swift. Use when writing idiomatic Swift with guard, value types, immutability, or naming conventions—not Swift concurrency/actor-isolation, persistence, linting, or release tooling.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.