Skip to content
Skills Library
Programming · Building & coding

assertion-density

/assertion-density

Place assertions where invariants are established or must hold: constructors, public boundaries, and loop bodies. Use when hardening code whose silent violations would otherwise surface far from their cause.

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

Place assertions where invariants are established or must hold: constructors, public boundaries, and loop bodies. Use when hardening code whose silent violations would otherwise surface far from their cause.

Original author description

Place assertions where invariants are established or must hold: constructors, public boundaries, and loop bodies. Use when hardening code whose silent violations would otherwise surface far from their cause.

How it works

  1. Method
  2. Litmus tests
  3. Boundaries
Original SKILL.md headings · 46 lines, 386 words
SKILL.md preview
---
name: assertion-density
description: "Place assertions where invariants are established or must hold: constructors, public boundaries, and loop bodies. Use when hardening code whose silent violations would otherwise surface far from their cause."
---

# Assertion density

An assertion is an executable claim about what must be true at a point in the
program, and its worth is proximity: it fails at the cause, not three stack
frames later where the bad value finally breaks something. Scattering asserts at
random adds noise; placing them where invariants actually live turns a class of
debugging sessions into one clear failure. The skill is knowing those places.

## Method

1. **Assert preconditions at every public boundary.** At the top of an exported
   function, check the arguments the caller must honor: `assert n >= 0`,
   non-null, index in range. A caller's mistake becomes a message at the door.
2. **Establish class invariants in the constructor.** After construction, assert
   the object sits in a legal state: `assert self.balance >= 0`, both ends of a
   range ordered. An object that cannot exist badly never spreads a bad state.
3. **Guard the loop invariant inside the loop.** Assert the property the loop
   maintains each pass: an index stays in bounds, a running sum stays
   non-negative, a heap stays ordered. The assert catches the pass that
   breaks it.
4. **Check postconditions before returning.** Ahead of `return result`, assert
   what you promised: the output is sorted, its length matches the input, no
   null slipped through. This defends the contract callers are about to rely
   on.
5. **Assert the impossible branch.** In an else or default you believe
   unreachable, write `assert False, "unreachable: " + state` rather than a
   silent pass. If reality disagrees, you learn at once and precisely.
6. **Keep assertions cheap and side-effect free.** Never `assert queue.pop()`:
   builds that strip asserts, like `python -O` or `NDEBUG`, would drop the pop
   too. Assert conditions; compute nothing the program itself depends on.

## Litmus tests

- When this assert fires, does the message point at the cause or a symptom?
- Would stripping assertions in a release build change any behavior? It must
  not.
- Can you name the invariant each assert defends in a sentence? If not, cut it.

## Boundaries

Assertions guard programmer errors, not user input or I/O failure: validate
untrusted data with real error handling that survives in production, since
asserts may compile out. Hot loops where an assert measurably costs throughput
are a judgment call; some teams gate expensive checks behind a debug flag.

Versions

The database has no other skills named assertion-density.

Database snapshot: 13.11.2026 · package version 70a317842622 (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

  • 100invariant-inference
    Automatically infer loop invariants for code verification and correctness proofs. Use when analyzing loops to identify properties that hold throughout execution, generating assertions for verification, proving loop correctness, or documenting loop behavior. Supports Python,…
  • 100architecture-md-writer
    Write or audit an ARCHITECTURE.md for agents: boundaries, invariants with verify commands, flows and a change guide. Use when creating or updating the architecture doc, or when agent changes keep landing in the wrong place; a UI style spec is the `design-md-writer` skill.

Feedback and reports

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