clean-code
Clean Code Skill
This skill embodies the principles of "Clean Code" by Robert C. Martin (Uncle Bob). Use it to transform "code that works" into "code that is clean."
🧠 Core Philosophy
"Code is clean if it can be read, and enhanced by a developer other than its original author." — Grady Booch
When to Use
Use this skill when:
- Writing new code: To ensure high quality from the start.
- Reviewing Pull Requests: To provide constructive, principle-based feedback.
- Refactoring legacy code: To identify and remove code smells.
- Improving team standards: To align on industry-standard best practices.
1. Meaningful Names
- Use Intention-Revealing Names:
elapsedTimeInDaysinstead ofd. - Avoid Disinformation: Don't use
accountListif it's actually aMap. - Make Meaningful Distinctions: Avoid
ProductDatavsProductInfo. - Use Pronounceable/Searchable Names: Avoid
genymdhms. - Class Names: Use nouns (
Customer,WikiPage). AvoidManager,Data. - Method Names: Use verbs (
postPayment,deletePage).
2. Functions
- Small!: Functions should be shorter than you think.
- Do One Thing: A function should do only one thing, and do it well.
- One Level of Abstraction: Don't mix high-level business logic with low-level details (like regex).
- Descriptive Names:
isPasswordValidis better thancheck. - Arguments: 0 is ideal, 1-2 is okay, 3+ requires a very strong justification.
- No Side Effects: Functions shouldn't secretly change global state.
3. Comments
- Don't Comment Bad Code—Rewrite It: Most comments are a sign of failure to express ourselves in code.
- Explain Yourself in Code:
vs# Check if employee is eligible for full benefits if employee.flags & HOURLY and employee.age > 65:if employee.isEligibleForFullBenefits(): - Good Comments: Legal, Informative (regex intent), Clarification (external libraries), TODOs.
- Bad Comments: Mumbling, Redundant, Misleading, Mandated, Noise, Position Markers.
4. Formatting
- The Newspaper Metaphor: High-level concepts at the top, details at the bottom.
- Vertical Density: Related lines should be close to each other.
- Distance: Variables should be declared near their usage.
- Indentation: Essential for structural readability.
5. Objects and Data Structures
- Data Abstraction: Hide the implementation behind interfaces.
- The Law of Demeter: A module should not know about the innards of the objects it manipulates. Avoid
a.getB().getC().doSomething(). - Data Transfer Objects (DTO): Classes with public variables and no functions.
6. Error Handling
- Use Exceptions instead of Return Codes: Keeps logic clean.
- Write Try-Catch-Finally First: Defines the scope of the operation.
- Don't Return Null: It forces the caller to check for null every time.
- Don't Pass Null: Leads to
NullPointerException.
7. Unit Tests
- The Three Laws of TDD:
- Don't write production code until you have a failing unit test.
- Don't write more of a unit test than is sufficient to fail.
- Don't write more production code than is sufficient to pass the failing test.
- F.I.R.S.T. Principles: Fast, Independent, Repeatable, Self-Validating, Timely.
8. Classes
- Small!: Classes should have a single responsibility (SRP).
- The Stepdown Rule: We want the code to read like a top-down narrative.
9. Smells and Heuristics
- Rigidity: Hard to change.
- Fragility: Breaks in many places.
- Immobility: Hard to reuse.
- Viscosity: Hard to do the right thing.
- Needless Complexity/Repetition.
🛠️ Implementation Checklist
- Is this function smaller than 20 lines?
- Does this function do exactly one thing?
- Are all names searchable and intention-revealing?
- Have I avoided comments by making the code clearer?
- Am I passing too many arguments?
- Is there a failing test for this change?
More from clubmediterranee/ai-core
git-commit
Execute git commit with conventional commit message analysis, intelligent staging, and message generation. Use when user asks to commit changes, create a git commit, or mentions "/commit". Supports: (1) Auto-detecting type and scope from changes, (2) Generating conventional commit messages from diff, (3) Interactive commit with optional type/scope/description overrides, (4) Intelligent file staging for logical grouping
14agent-browser
Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction.
12skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.
12react-best-practices
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
12typescript-advanced-types
Master TypeScript's advanced type system including generics, conditional types, mapped types, template literals, and utility types for building type-safe applications. Use when implementing complex type logic, creating reusable type utilities, or ensuring compile-time type safety in TypeScript projects.
12trident-icons
Find and use icons from the @clubmed/trident-icons library. Use when a user asks which icon to use for a given concept, writes <Icon name= without knowing the right name, mentions "@clubmed/trident-icons", asks "quelle icône pour X", "which icon for Y", "find me an icon", "what icon represents Z", "liste les icônes de transport", or needs import code for Trident icons. Also triggers when writing or reviewing a component that should display an icon from the Club Med design system.
10