clean-code-functions
Skill3 starsChanged 8 months agoMITView on GitHub
Clean Code function design principles for Go. Use when creating, editing, or reviewing Go functions and methods. Triggers on new function definitions, refactoring existing functions, adding parameters, or when a function is growing in size or complexity.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- lifeodyssey/craftsmanship-skillstheir own version, first seen Apr 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
- lifeodyssey/craftsmanship-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-designSkill
- clean-code-errorsSkill
- 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
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 8 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
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
If a function is hard to name, it's doing too much — split it
- Distinctive: line 15
If you need to scroll to see the whole function, it's too long
- Distinctive: line 22
If you can extract a meaningful sub-function, the original was doing more than one thing
- Distinctive: line 26
Don't mix orchestration with implementation detail in the same function
- Distinctive: line 59
Use functional options pattern for optional configuration in public APIs
- Very specific: line 71
If named Validate, it should not also modify the input
- Very specific: line 72
If named Get, it should not create a record if missing (unless explicitly named GetOrCreate)
- Distinctive: line 74
If side effects are necessary, make them explicit in the name
- Distinctive: line 91
Use named returns sparingly — only when they clarify what is returned in a complex signature
- Distinctive: line 97
If a function cannot be traced to a spec requirement, question whether it's needed (YAGNI)
≈ “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 Functions for Go
Apply these principles when writing or modifying Go functions.
Size
- Functions should be small — aim for under 30 lines of logic
- If a function is hard to name, it's doing too much — split it
- If you need to scroll to see the whole function, it's too long
- Extract sections guarded by comments into their own functions — the comment is the name
Single Responsibility
- A function does ONE thing at ONE level of abstraction
- "One thing" means: one reason for someone to read or change this function
- If you can extract a meaningful sub-function, the original was doing more than one thing
Single Level of Abstraction (SLA)
- Don't mix orchestration with implementation detail in the same function
- Top-level functions should read like a high-level description:
func (s *Server) HandleDeploy(ctx context.Context, req DeployRequest) error { target, err := s.resolveTarget(req) if err != nil { return fmt.Errorf("resolve target: %w", err) } if err := s.validate(target); err != nil { return fmt.Errorf("validate: %w", err) } return s.deploy(ctx, target) } - Lower-level functions handle the detail
Arguments
- Fewer is better: zero, one, or two arguments are ideal
- Three or more arguments — consider a config/options struct:
// Instead of: func Connect(host string, port int, timeout time.Duration, tls bool) error // Use: type ConnectConfig struct { Host string Port int Timeout time.Duration TLS bool } func Connect(cfg ConnectConfig) error - Use functional options pattern for optional configuration in public APIs
context.Contextis always the first parameter and doesn't count toward the limit
Command-Query Separation
- A function should either DO something (command) or RETURN something (query), not both
- Commands:
Save,Delete,Send— returnerroronly - Queries:
Get,Find,List— return data +error - Exception: Go's
okidiom is fine:val, ok := m[key]
No Side Effects
- If named
Validate, it should not also modify the input - If named
Get, it should not create a record if missing (unless explicitly namedGetOrCreate) - Functions should not depend on or modify hidden state
- If side effects are necessary, make them explicit in the name
Return Values
- Return early on errors — avoid deep nesting:
// Good if err != nil { return err } // continue happy path // Bad if err == nil { // nested happy path } - Use named returns sparingly — only when they clarify what is returned in a complex signature
- Return concrete types from constructors, accept interfaces as parameters
Spec Traceability
- Each spec acceptance criterion should map to one or a small cluster of functions
- If a function cannot be traced to a spec requirement, question whether it's needed (YAGNI)
- The function name should make the spec connection obvious
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.

