For writing clean functions: start with docstring, iterate until code matches docstring exactly, achieve docstring-code isomorphism.
return x + 1)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!
# 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]
npx skills add jimmc414/write-docstring-first下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer