Skip to content
Skills Library
Programming · Building & coding

clean-functions

/clean-functions

Write functions that do one thing and are obvious from the outside — at most three arguments, no output arguments, no flag arguments, no dead functions, one level of abstraction, guard clauses over nesting (F1-F4, G30, G34). Use when writing or refactoring functions, components or handlers, and on long parameter lists, boolean parameters, deep nesting or unused exports.

Licence
MIT
Last repository change
11.11.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
1
Deprecation

No signals detected. Repository changed on 11.11.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Write functions that do one thing and are obvious from the outside — at most three arguments, no output arguments, no flag arguments, no dead functions, one level of abstraction, guard clauses over nesting (F1-F4, G30, G34). Use when writing or refactoring functions, components or handlers, and on long parameter lists, boolean parameters, deep nesting or unused exports.

Original author description

Write functions that do one thing and are obvious from the outside — at most three arguments, no output arguments, no flag arguments, no dead functions, one level of abstraction, guard clauses over nesting (F1-F4, G30, G34). Use when writing or refactoring functions, components or handlers, and on long parameter lists, boolean parameters, deep nesting or unused exports.

How it works

  1. F1 — At most three arguments
  2. F2 — No output arguments
  3. F3 — No flag arguments
  4. F4 — Delete dead functions
  5. G30 / G34 — One thing, one level of abstraction
  6. Guard clauses over nesting
  7. Command–query separation
  8. Checklist
Original SKILL.md headings · 116 lines, 652 words
SKILL.md preview
---
name: clean-functions
description: Write functions that do one thing and are obvious from the outside — at most three arguments, no output arguments, no flag arguments, no dead functions, one level of abstraction, guard clauses over nesting (F1-F4, G30, G34). Use when writing or refactoring functions, components or handlers, and on long parameter lists, boolean parameters, deep nesting or unused exports.
---

# Clean functions

A function should be small, do one thing, and be understandable from its signature without reading its body.

## F1 — At most three arguments

Beyond three, the call site stops being readable and the order becomes a trap.

```ts
// Bad — what does the fourth boolean mean at the call site?
createUser(name, email, age, country, timezone, language, true)

// Good — named, reorderable, extensible
type NewUser = {
  name: string
  email: string
  country: string
  timezone: string
  subscribeToNewsletter: boolean
}
function createUser(user: NewUser) { … }
```

Two or more arguments of the same type side by side are a bug waiting to happen (`copy(source, target)` — which way round?). Name them in an object or encode the direction in the function name.

The same rule applies to UI component props: past a handful, group them.

## F2 — No output arguments

A function should return its result, not reach into its inputs and mutate them. Mutation through a parameter is invisible at the call site.

```ts
// Bad — caller cannot tell their object was changed
function appendFooter(report: Report): void {
  report.content += FOOTER
}

// Good
function withFooter(report: Report): Report {
  return { ...report, content: `${report.content}${FOOTER}` }
}
```

Where the language and codebase genuinely favour in-place mutation for performance, make it obvious in the name (`sortInPlace`, `mutateX`) and keep it local.

## F3 — No flag arguments

A boolean parameter means the function does at least two things, and the call site reads as a riddle.

```ts
render(true)                    // true what?

renderTestPage()                // two functions, each doing one thing
renderProductionPage()
```

If the two paths share most of their work, extract the shared part and let the two entry points call it. Where a parameter genuinely selects among several modes, use a named union — `render(mode: "test" | "production")` — never a bare boolean.

## F4 — Delete dead functions

If nothing calls it, delete it. No "just in case", no commented-out body, no `_old` suffix. Version control remembers.

Check properly before deleting: dynamic dispatch, string-keyed registries, dependency injection, framework conventions, public package exports and tests can all be real callers that a naive search misses.

## G30 / G34 — One thing, one level of abstraction

If you can extract another function with a meaningful name, the original was doing more than one thing. Mixing levels — high-level orchestration interleaved with byte-twiddling or SQL string building — forces the reader to change gear mid-paragraph.

A reliable test: can you describe what the function does in one sentence, without "and"?

## Guard clauses over nesting

Handle the exceptional cases first and return early. Deep nesting hides the main path.

```ts
// Bad
function price(order) {
  if (order) {
    if (order.items.length > 0) {
      if (order.customer) {
        …
      }
    }
  }
}

// Good
function price(order: Order): Money {
  if (!order.items.length) return Money.zero
  if (!order.customer) throw new MissingCustomerError(order.id)
  …
}
```

Three levels of indentation is a smell; four is a refactor.

## Command–query separation

A function either answers a question or changes something — not both. `isValid()` must not persist. `save()` must not return a different object than you expect. When a function must do both, the name has to say so (`N7`).

## Checklist

- [ ] Three arguments or fewer, and no same-typed pair that could be swapped? (F1)
- [ ] Returns its result rather than mutating inputs? (F2)
- [ ] No boolean flag selecting between behaviours? (F3)
- [ ] Every function here actually called? (F4)
- [ ] Describable in one sentence without "and"? (G30)
- [ ] One level of abstraction throughout? (G34)
- [ ] Guard clauses instead of nesting, three levels or fewer?
- [ ] Queries do not command, and commands do not pretend to be queries?

---

Derived from [clean-code-skills](https://github.com/ertugrul-dmr/clean-code-skills#clean-code-skills-for-ai-agents) (MIT), adapted to be language-neutral. Full catalogue and sync record: `clean-code`. To re-sync: `clean-code-update`.

Versions

The database has no other skills named clean-functions.

Database snapshot: 13.11.2026 · package version d3bd14bfb3b3 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100devops-cleanup
    Behavior-preserving code cleanup driven by a plain-English statement: reduce comments, replace duplicated code with calls to one implementation, split large functions into helpers, cut nesting and long parameter lists, delete dead and commented-out code. Researchers scan and…
  • 100code-simplification
    Use when code works but is harder to read, maintain, or extend than it should be — after a feature lands, when review flags complexity, or when you hit deep nesting, long functions, high cyclomatic complexity, functions too tangled to test, two functions that do nearly the same…
  • 100most-parameters
    Find the functions/methods with the most parameters in a codebase, ranked by parameter count, using ast-grep structural matching. Use whenever the user wants to know which functions take too many arguments, asks "what has the most parameters / longest argument list", hunts for…
  • 84analyze-dead-code
    Find and remove dead code — unused exports, unreachable modules, and stale files. Always use this skill whenever the user says "find dead code", "remove unused code", "clean up unused exports", "what code can we delete", "detect unreachable code", "what files are no longer…
  • 100dead-code-removal
    Use when unused functions, classes, exports, or files need to be identified and safely deleted.
  • 100r-lifecycle
    Guidance for managing R package lifecycle according to tidyverse principles using the lifecycle package. Use when: (1) Setting up lifecycle infrastructure in a package, (2) Deprecating functions or arguments, (3) Renaming functions or arguments, (4) Superseding functions, (5)…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.