clean-code-design
Skill3 starsChanged 8 months agoMITView on GitHub
Clean Code design maxims for Go — DRY, KISS, YAGNI, separation of concerns, composition over inheritance, Law of Demeter. Use when making architectural decisions, creating new packages or modules, refactoring code structure, or reviewing overall code organization in Go projects.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- cathaysia/skillstheir own version, first seen Oct 23, 2026
- masonhuemmer/dopsword for word, first seen Mar 24, 2026
Other versions2 projects use a version of this.
Word for word · 1
- masonhuemmer/dops★ 3100% same
Edited · 0
None found.
Wrote their own version · 1
- cathaysia/skills★ 2same 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 repository19 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- bubbletea-patternsSkill
- charm-stylingSkill
- clean-code-boundariesSkill
- clean-code-errorsSkill
- clean-code-functionsSkill
- clean-code-namingSkill
- clean-code-solidSkill
- clean-code-testingSkill
- cli-structureSkill
- create-runbookSkill
- demo-recordingSkill
- mutation-testingSkill
- shell-scriptsSkill
- spec-workflowSkill
- tdd-workflowSkill
- tui-layoutSkill
- tui-testingSkill
- wizard-formsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
17 rules. About 0 are common, 15 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈15
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Do not add configuration options "in case someone needs them later"
- Distinctive: line 15
Do not build plugin architectures, feature flags, or extension points speculatively
- Distinctive: line 16
If it's not in the spec, it doesn't get built.
- Distinctive: line 24
If a junior developer can't understand the code in 5 minutes, it's too complex
- Distinctive: line 29
Every piece of domain knowledge has a single authoritative representation
- Distinctive: line 31
Before extracting, ask: "If one of these changes, must the other change too?" If no, they're not duplicates.
- Distinctive: line 33
Do NOT apply DRY to tests — test readability beats test DRYness
- Distinctive: line 38
Do not mix I/O with business logic:
- Distinctive: line 60
Use struct embedding for code reuse, interfaces for polymorphism
- Distinctive: line 61
Prefer small, composable types over large monolithic ones:
- Very specific: line 75
No train wrecks: s.config.Database.Connection.Pool.Get() — each .
- Distinctive: line 76
If you need data deep inside a structure, expose a method at the right level:
- Distinctive: line 90
Avoid circular dependencies — if A imports B and B needs A, extract an interface package
- Very specific: line 92
Keep main.go thin: parse flags, wire dependencies, call Run()
- Distinctive: line 96
When implementing a spec, clean up the code you touch
- Distinctive: line 98
Don't refactor unrelated code — scope cleanup to what you're working on
- Distinctive: line 108
When in conflict, higher-numbered rules yield to lower-numbered ones.
≈ “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.
Files
Clean Code Design Principles for Go
Apply these principles when making structural or architectural decisions.
YAGNI — You Aren't Gonna Need It
- Implement only what the current spec requires — nothing more
- Do not add configuration options "in case someone needs them later"
- Do not build plugin architectures, feature flags, or extension points speculatively
- If it's not in the spec, it doesn't get built. Period.
- The cost of building the wrong abstraction is higher than the cost of adding it later
KISS — Keep It Simple
- The simplest solution that satisfies the spec is the best solution
- Three similar lines of code are better than a premature abstraction
- Choose boring technology over clever technology
- If a junior developer can't understand the code in 5 minutes, it's too complex
- Complexity debt compounds faster than technical debt
DRY — Don't Repeat Yourself
- Every piece of domain knowledge has a single authoritative representation
- DRY applies to knowledge, not just code — identical-looking code serving different purposes is NOT duplication
- Before extracting, ask: "If one of these changes, must the other change too?" If no, they're not duplicates.
- Apply DRY across: code, config, specs, build scripts
- Do NOT apply DRY to tests — test readability beats test DRYness
Separation of Concerns
- Each package has one clear purpose
- Do not mix I/O with business logic:
// Bad: business logic mixed with I/O func ProcessConfig(path string) error { data, err := os.ReadFile(path) // I/O // ... validation logic ... // business logic // ... transformation ... // business logic return os.WriteFile(out, result, 0644) // I/O } // Good: separated func LoadConfig(path string) ([]byte, error) { ... } // I/O func ValidateConfig(data []byte) error { ... } // logic func TransformConfig(data []byte) ([]byte, error) { ... } // logic func SaveConfig(path string, data []byte) error { ... } // I/O - CLI parsing, business logic, and infrastructure are separate layers
- For a Go CLI:
cmd/(CLI wiring) →internal/(business logic) → adapters (I/O, external services)
Composition Over Inheritance
- Go has no inheritance — this principle is built into the language
- Use struct embedding for code reuse, interfaces for polymorphism
- Prefer small, composable types over large monolithic ones:
// Compose behaviors type DeployService struct { validator Validator pusher Pusher notifier Notifier } - Favor function parameters and return values over method receivers when behavior doesn't need state
Law of Demeter
- A function should only call methods on: its receiver, its parameters, objects it creates, its direct fields
- No train wrecks:
s.config.Database.Connection.Pool.Get()— each.is a coupling point - If you need data deep inside a structure, expose a method at the right level:
// Bad pool := s.config.Database.Connection.Pool conn := pool.Get() // Good conn, err := s.GetDBConnection()
Package Design
- Packages are the unit of encapsulation in Go
- Name packages by what they provide, not what they contain
- Avoid circular dependencies — if A imports B and B needs A, extract an interface package
internal/enforces visibility at the compiler level — use it- Keep
main.gothin: parse flags, wire dependencies, callRun()
Boy Scout Rule
- When implementing a spec, clean up the code you touch
- Rename a confusing variable, extract a function, remove dead code
- Don't refactor unrelated code — scope cleanup to what you're working on
- Small, continuous improvements prevent decay
Kent Beck's Four Rules of Simple Design (Priority Order)
- Runs all the tests — all spec criteria pass
- Contains no duplication — shared concepts implemented once
- Expresses intent — code reads like the spec
- Minimizes classes/functions — no unnecessary abstractions
When in conflict, higher-numbered rules yield to lower-numbered ones.
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
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.

