agentsclimarketplace

Clean code functions

Skill lifeodyssey/craftsmanship-skills/skills/clean-code-functions

Agent Skills distilled from Clean Code & Refactoring. Install: npx skills add lifeodyssey/craftsmanship-skills

Install
npx -y skills add lifeodyssey/craftsmanship-skills --skill clean-code-functions

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Use when designing, reviewing, or refactoring functions — applies Clean Code function principles for small, focused, well-argumented functions

SKILL.md

3.1 KB, as published. Nobody here has run it

Clean Code: Functions

Based on Robert C. Martin's Clean Code, Chapter 3: Functions.

When to Use This Skill

Trigger on:

  • Writing or reviewing function design
  • Functions that are too long, do too much, or have too many arguments
  • "Should I extract this into a function?" questions
  • Debates about function size and structure

Rules

1. Functions Should Be Small

The first rule of functions is they should be small. The second rule is they should be smaller than that. Functions should rarely be longer than 20 lines.

2. Do One Thing

A function should do one thing, do it well, and do it only. If you can extract another function with a meaningful name, the original is doing more than one thing.

# Bad — does two things
def process_user(user):
    # validates
    if not user.email:
        raise ValueError("Email required")
    # saves
    db.save(user)

# Good — one thing each
def validate_user(user):
    if not user.email:
        raise ValueError("Email required")

def save_user(user):
    db.save(user)

3. One Level of Abstraction

All statements in a function should be at the same level of abstraction. Don't mix high-level business logic with low-level implementation details.

4. The Stepdown Rule

We want every function to be followed by those at the next level of abstraction, reading top-down like a newspaper article.

5. Use Descriptive Names

A long descriptive name is better than a short enigmatic name. If you have a well-named function, comments are often redundant.

6. Function Arguments

The ideal number of arguments is zero (niladic). One is fine (monadic). Two is ok (dyadic). Three should be avoided (triadic). More than three requires special justification.

# Bad
def make_circle(x, y, radius, color, stroke_width, fill): ...

# Good
def make_circle(center: Point, radius: float, style: CircleStyle): ...

7. Avoid Flag Arguments

Boolean arguments loudly declare the function does more than one thing.

# Bad
def render_page(is_uppercase):
    if is_uppercase:
        ...render uppercase...

# Good
def render_uppercase_page():
    ...
def render_lowercase_page():
    ...

8. No Side Effects

A function should do what its name says. Hidden side effects create temporal couplings and order dependencies.

9. Command Query Separation

A function should either do something or answer something, but not both. Either change state or return data.

10. Extract Try/Catch Blocks

Try/catch bodies are ugly. Extract the body into a function of its own.

Quick Checklist

  • Is it under 20 lines?
  • Does it do one thing?
  • Are all statements at the same abstraction level?
  • Does it have 0-2 arguments?
  • Does it have no hidden side effects?
  • Is the name descriptive enough to avoid comments?
  • Does it either change state or return data, not both?

Source

Distilled from Clean Code by Robert C. Martin, Chapter 3: Functions.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.