agentleFS
nuttakulsvnuttakulsv/think-like/skills/dijkstra/SKILL.md

dijkstra

Skill2 starsChanged 41 days agoMITView on GitHub

Edsger Dijkstra's discipline for code that must be correct: reason about it before testing it, write down the invariant, keep each piece small enough to hold in your head, and avoid clever tricks. Use for algorithms, concurrency, money and inventory logic, state machines, loops with tricky bounds, and reviewing code where a bug would be expensive. Triggers: "think like Dijkstra", "prove it works", "is this correct", "invariant", "edge cases", "คิดแบบไดก์สตรา", "พิสูจน์ว่าถูก", "โค้ดนี้ถูกจริงไหม". Not for quick throwaway scripts.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. abxn4r/archon-skills★ 1same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository25 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Simplify until the argument is short: If the reasoning needs a page, restructure the code: fewer special cases, smaller functions, one …

    line 35
  2. Distinctive:

    Write in the user's language.

    line 45

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Think like Dijkstra

Turing Award winner (1972) behind shortest paths, semaphores and structured programming. He argued that tests can show bugs are present but never that they are absent, so correctness has to come from reasoning, and the program has to be simple enough to reason about.

When to use

  • Loops, indexes, ranges, off-by-one territory
  • Anything with money, stock counts, permissions, or concurrent updates
  • A test suite is green but you still don't trust the code
  • Reviewing a clever piece of code

Method

  1. State the contract. Precondition (what must be true on entry), postcondition (what is true on exit), in terms of the data, not the code.
  2. Find the invariant for every loop, retry, or long-lived state: what stays true at every step? Write it down as a sentence and, where cheap, as an assertion.
  3. Argue each step. Show that the invariant holds initially, is preserved by each iteration or transition, and together with the exit condition implies the postcondition. Show termination (what decreases each step?).
  4. Hunt the boundaries: empty input, one element, maximum size, duplicates, concurrent callers, the step after the last.
  5. Simplify until the argument is short. If the reasoning needs a page, restructure the code: fewer special cases, smaller functions, one responsibility each. Remove clever tricks that make the argument longer.
  6. Then test, aiming tests at the boundaries and the invariant, not at the happy path you already proved.

Output

  • Contract: pre and post in one line each
  • Invariant: the sentence (and the assertion if added)
  • Argument: init / preserve / exit / terminate, one line each
  • Boundaries checked: list with result
  • Changes: simplifications made so the argument fits, and tests added
  • Write in the user's language.

Anti-patterns

  • "The tests pass" offered as proof of correctness
  • Clever one-liners whose correctness nobody can explain
  • Fixing an edge case with an extra if instead of finding the invariant it violates
  • Concurrency handled by "it's unlikely"

Example (illustration)

User: Review this function that moves stock between warehouses.

Contract: pre: qty > 0, source has ≥ qty. post: total stock unchanged; source −qty, target +qty.

Invariant: sum of stock across warehouses is constant at every committed state.

Argument: the code reads source stock, checks it, then writes two updates in separate transactions. Between the two writes the invariant is broken, and a crash leaves stock destroyed. Two concurrent moves can both pass the check (read-then-write race).

Changes: one transaction; UPDATE stock SET qty = qty - $1 WHERE id = $2 AND qty >= $1 and check the affected row count instead of reading first. The invariant now holds at every commit. Tests added: concurrent moves of the last unit, qty = 0, qty = available.

Sources

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.