agentleFS
rundopsrundops/dops/.claude/skills/clean-code-functions/SKILL.md

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

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
  1. Distinctive:

    If a function is hard to name, it's doing too much — split it

    line 14
  2. Distinctive:

    If you need to scroll to see the whole function, it's too long

    line 15
  3. Distinctive:

    If you can extract a meaningful sub-function, the original was doing more than one thing

    line 22
  4. Distinctive:

    Don't mix orchestration with implementation detail in the same function

    line 26
  5. Distinctive:

    Use functional options pattern for optional configuration in public APIs

    line 59
  6. Very specific:

    If named Validate, it should not also modify the input

    line 71
  7. Very specific:

    If named Get, it should not create a record if missing (unless explicitly named GetOrCreate)

    line 72
  8. Distinctive:

    If side effects are necessary, make them explicit in the name

    line 74
  9. Distinctive:

    Use named returns sparingly — only when they clarify what is returned in a complex signature

    line 91
  10. Distinctive:

    If a function cannot be traced to a spec requirement, question whether it's needed (YAGNI)

    line 97

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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.Context is 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 — return error only
  • Queries: Get, Find, List — return data + error
  • Exception: Go's ok idiom 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 named GetOrCreate)
  • 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

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.