programming
Before writing, changing, or fixing any code in any language, read this guide of design principles (deep modules, functional core and imperative shell, explicit dependencies, modular monolith). It applies under any workflow skill, including test-first ones, and does not define a test loop.
- License 许可
- MIT
- 最近更新
- 2026-11-08
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- programming
- description
- Before writing, changing, or fixing any code in any language, read this guide of design principles (deep modules, functional core and imperative shell, explicit dependencies, modular monolith). It applies under any workflow skill, including test-first ones, and does not define a test loop.
02 资源文件 1
- 参考文档evals/evals.json1.1 KB
03 SKILL.md 正文
Programming
Design principles for any code change. Read them before the first edit, then let whatever workflow is running (a test-first skill, /implement, a plain request) drive the steps.
Constraints
- These principles are defaults. A project's established conventions and its own CLAUDE.md win where they conflict. Apply each principle only where the language supports it, and when one would make the code worse, depart from it and say why in your closing note.
- Read the project's glossary (
GLOSSARY.mdorCONTEXT.md) and the ADRs (Architecture Decision Records) for the area you touch, if they exist, so names match the domain and no recorded decision is undone. - Change only what the task needs. Point out problems in existing code instead of refactoring them unasked.
- Scale the principles to the code's size and lifespan. A throwaway script or operational glue (provisioning, build configuration, dotfiles) needs readable code and little else.
Principles
-
Simplicity first (YAGNI, "you aren't gonna need it"). Write the code that is easiest to read and reason about. Add an abstraction when a second real use case needs it, not in anticipation of one.
-
Deep modules, packaged by feature, toward a modular monolith. A module is anything with an interface and an implementation, from a function to a package. Make it deep: a lot of behaviour behind a small interface, where the interface is everything a caller must know (signature, invariants, ordering, error modes). Organise code around domain concepts (
Order,Invoice) rather than technical layers (router,service,model). Each module keeps its internals and data private, and other modules reach it only through its interface. Apply the deletion test: if deleting a module would make its complexity vanish, it was a pass-through, and if the complexity would reappear across its callers, it earns its keep. Prefer the words module, interface, seam and adapter over component, service, API and boundary. -
Composition over inheritance. Build behaviour from small functions, closures, and interfaces, using structural or duck typing where the language has it. Closures and modules encapsulate state; keep class hierarchies shallow.
-
Explicit dependencies. Pass collaborators in as arguments or closures, so a function's signature shows everything it depends on and a test can substitute any of them at a system boundary. That includes the clock, random source, and ID generator, so a result never depends on when or where it runs.
-
SOLID, applied with functions and modules rather than classes:
- Single responsibility: each function or module has one reason to change.
- Open/closed: extend behaviour by passing in a function or adding a new variant, leaving working code unedited.
- Liskov substitution: every implementation of an interface honours its whole contract, including errors and edge cases.
- Interface segregation: keep interfaces small and define them in the module that consumes them, not the one that implements them.
- Dependency inversion: core logic depends on interfaces it defines, and the I/O adapters at the edge implement them. Add such a port only when two adapters are justified, typically production and test. One adapter is a hypothetical seam and just adds indirection.
-
Functional core, imperative shell. Keep business logic as pure functions over data, and do I/O and mutation in a thin outer layer that calls them. Return results instead of producing side effects, which keeps interfaces easy to test. Accept a few pragmatic side effects in the core when purity would need monad-style plumbing. If a test of new code needs many mocks, the code mixes decisions with I/O: split it into a pure core and a thin shell (the Humble Object pattern) instead of mocking around it.
-
Immutable by default. Return new values instead of mutating existing ones; immutable data makes concurrent code far easier to reason about.
-
Make illegal states unrepresentable. Model states with the type system (enums, sum types, exhaustive pattern matching) so invalid combinations fail at compile time instead of relying on runtime checks alone. Represent "no value" explicitly (
Option,Maybe, or strictly checked nullable types) and check it at the earliest point. Stop before this needs advanced type-level machinery. -
Specific errors, wrapped with context, handled at boundaries. Define an error type for each failure a caller can act on. Wrap errors with context as they propagate ("loading invoice 42: connection refused"). Handle them (log, retry, translate into a response) only at system boundaries such as HTTP handlers, CLI entry points, and job runners; business logic lets them propagate.
Seams for tests
A seam is the public interface where a module's behaviour can be observed without reaching inside. Tests that a workflow skill asks for go through seams, use real collaborators, and mock only at system boundaries: third-party APIs, email and message buses, the clock, randomness, and sometimes the file system. Your own modules are never mocked.
04 同仓库更多 Skills
writing-studio
Write or review professional, human-facing prose so the result is clear, well-structured, correctly shaped for its document type, and free of AI-sounding filler. Use this skill WHENEVER you are about to write something a person will read (a proposal, email, chat or Slack message, document or wiki page, blog post, announcement, status update, RFC or design doc, release notes, exec brief, incident report, peer performance feedback, RACI or roles-and-responsibilities matrix, program or project poster, PR/FAQ or working-backwards doc) OR when asked to review, improve, polish, critique, proofread, tighten, sharpen, or shorten any existing text. Prefer it over ad-hoc style fixes, especially for multi-paragraph or long-form writing. Do NOT use it for code, code comments, commit messages, machine-readable data (JSON/YAML/CSV), or trivial one-line replies.
workflow-step-numbering
Fixture with non-sequential step numbering to verify R011 fires.
workflow-no-steps
Fixture whose Workflow has no Step sub-headings to verify R010 fires.
valid-skill
A fully compliant fixture skill used to verify skill-linter passes a clean SKILL.md without findings.
section-out-of-order
Fixture with Workflow before When to use to verify R007 fires.
references-with-binary
Fixture whose references directory contains a non-text file to verify R025 fires.