Skip to content
Back to skills

Extract Function

ASecurity

Pull a cohesive block of code into a well-named function or method

  • 3 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 3, 2026
ai-agentsgorefactoring

Security analysis

A100/100

Scanned September 3, 2026

npx -y skills add black141312/ada --skill extract-function --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Extract Function?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Extract Function
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/black141312-extract-function/badge)](https://www.skillsdirectory.com/skills/black141312-extract-function)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: extract-function
description: Pull a cohesive block of code into a well-named function or method
category: refactoring
---

# Extract Function

Use when a function is too long, a block needs a comment to explain it, or the same logic is about to be reused. A good extraction names the "what" so the caller reads like prose.

1. Identify the exact block to extract and confirm it is cohesive (one job, clear boundary).
2. Determine inputs (variables read) and outputs (variables written/returned after the block).
3. Create the new function with those inputs as parameters and the outputs as return value(s).
4. Replace the original block with a call; pass arguments and assign results back.
5. Name the function for its intent, not its mechanics (`computeTax`, not `doStep2`).
6. Run tests; the behavior and outputs must be identical.

## Rules
- If the block writes more than one or two outer variables, return a small object/tuple instead of using side effects.
- Keep the new function pure when feasible — pass dependencies in rather than reaching for globals.
- Don't over-parameterize; if a value is constant at the call site, inline it.
- Place the new function at a sensible scope (same module/class) before reaching for shared utils.
- Preserve early returns and error paths exactly; extracting can silently swallow a `return`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…