Docstring Fixpoint Theory: Iterate between docstring and code until they are isomorphic - each reads like a translation of the other.
# Step 1: Write docstring as specification
def rainfall(numbers):
"""Return the mean of the non-negative values in a list,
up to the first -999 (if it shows up)."""
...
# Step 2: Write code that mirrors the docstring
def rainfall(numbers):
"""Return the mean of the non-negative values in a list,
up to the first -999 (if it shows up)."""
return mean(non_negative(upto(-999, numbers)))
# Notice: docstring and code are almost the same sentence!
Example (from pytudes DocstringFixpoint.ipynb)
# The Rainfall Problem - evolved through fixpoint iteration
# Version 1: Problem statement as docstring
def rainfall(numbers):
"""Design a program called rainfall that consumes a list of numbers
representing daily rainfall amounts. The list may contain -999
indicating end of data. Produce the average of non-negative values
up to the first -999."""
...
# Version 2: Simplified docstring
def rainfall(numbers):
"""Produce the average of the non-negative values in a list,
up to the first -999 (if it shows up)."""
...
# Version 3: Code mirrors docstring
def rainfall(numbers):
"""Return the mean of the non-negative values in a list,
up to the first -999 (if it shows up)."""
return mean(non_negative(upto(-999, numbers)))
# Helper functions (each with its own fixpoint)
def upto(sentinel, items):
"""Return items that appear before sentinel,
or all items if sentinel doesn't appear."""
return items[:items.index(sentinel)] if sentinel in items else items
def non_negative(numbers):
"""The numbers that are >= 0."""
return [x for x in numbers if x >= 0]
Key Principles
Docstring first: Specification before implementation
Iterate both ways: Edit docstring, then code, then docstring...
Match vocabulary: Use same words in both
Helpers inherit pattern: Each has its own docstring-code match
Fixpoint = done: When neither needs changing, you're done
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: jimmc414-claude-code-plugin-marketplace-write-docstring-firs3description: write-docstring-first4---56# write-docstring-first78## When to Use9- Writing any new function10- When clarity of purpose matters11- Complex logic that needs explanation12- Functions that will be reused13- Teaching or educational code1415## When NOT to Use16- Trivial one-liners (`return x + 1`)17- Private implementation details18- Rapidly prototyping (add later)1920## The Pattern2122**Docstring Fixpoint Theory**: Iterate between docstring and code until they are isomorphic - each reads like a translation of the other.2324```python25# Step 1: Write docstring as specification26def rainfall(numbers):27 """Return the mean of the non-negative values in a list,28 up to the first -999 (if it shows up)."""29 ...3031# Step 2: Write code that mirrors the docstring32def rainfall(numbers):33 """Return the mean of the non-negative values in a list,34 up to the first -999 (if it shows up)."""35 return mean(non_negative(upto(-999, numbers)))3637# Notice: docstring and code are almost the same sentence!38```3940## Example (from pytudes DocstringFixpoint.ipynb)4142```python43# The Rainfall Problem - evolved through fixpoint iteration4445# Version 1: Problem statement as docstring46def rainfall(numbers):47 """Design a program called rainfall that consumes a list of numbers48 representing daily rainfall amounts. The list may contain -99949 indicating end of data. Produce the average of non-negative values50 up to the first -999."""51 ...5253# Version 2: Simplified docstring54def rainfall(numbers):55 """Produce the average of the non-negative values in a list,56 up to the first -999 (if it shows up)."""57 ...5859# Version 3: Code mirrors docstring60def rainfall(numbers):61 """Return the mean of the non-negative values in a list,62 up to the first -999 (if it shows up)."""63 return mean(non_negative(upto(-999, numbers)))6465# Helper functions (each with its own fixpoint)66def upto(sentinel, items):67 """Return items that appear before sentinel,68 or all items if sentinel doesn't appear."""69 return items[:items.index(sentinel)] if sentinel in items else items7071def non_negative(numbers):72 """The numbers that are >= 0."""73 return [x for x in numbers if x >= 0]74```7576## Key Principles771. **Docstring first**: Specification before implementation782. **Iterate both ways**: Edit docstring, then code, then docstring...793. **Match vocabulary**: Use same words in both804. **Helpers inherit pattern**: Each has its own docstring-code match815. **Fixpoint = done**: When neither needs changing, you're done8283---84> Converted and distributed by [TomeVault](https://tomevault.io/claim/jimmc414) — claim your Tome and manage your conversions.85<!-- tomevault:4.0:skill_md:2026-04-13 -->
Run npx skillmds@latest add tomevault-io/jimmc414-claude-code-plugin-marketplace-write-docstring-firs in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
write-docstring-first It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.