본문으로 건너뛰기
cccskills
무료GitHub에 공개

clean-code

Applies battle-tested clean code principles to writing, reviewing, and refactoring code. Covers naming, functions, comments, error handling, class design, and the critical difference between clever code and clear code.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(2)

  • SKILL.md7.0 KB
  • references/typescript.md3.2 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Clean Code

Code is read 10x more than it's written. Every naming choice, every function boundary, every abstraction layer either helps or hurts the next person who reads it — including future you.

When to Use

  • Writing any new code
  • Reviewing pull requests
  • Refactoring existing code
  • When code "works but feels wrong"

Stack-Specific References

The principles below are language-agnostic. For idiomatic patterns and syntax, read the reference matching your surface's Languages column:

LanguageReference
TypeScript / JavaScriptreferences/typescript.md
Pythonreferences/python.md
Goreferences/go.md
Rustreferences/rust.md

Core Principles

1. Names Are Documentation

Names should reveal intent. If a name requires a comment to explain it, the name is wrong.

BadGoodWhy
delapsedDaysWhat is d?
listactiveUsersWhat kind of list?
processData()validateAndSaveOrder()What processing?
tempfilteredResultsTemporary what?
flagisEligibleForDiscountWhat flag?
doStuff()sendWelcomeEmail()What stuff?
ManagerOrderProcessorManager of what?
UtilsStringFormatterUtil for what?

Rules:

  • Classes/types → nouns (UserRepository, PaymentGateway)
  • Functions → verbs (calculateTotal, sendNotification)
  • Booleans → questions (isActive, hasPermission, canEdit)
  • Constants → screaming snake with context (MAX_RETRY_ATTEMPTS, not MAX)
  • No abbreviations unless universally understood (id, url, api are fine; usr, mgr, proc are not)

2. Functions Should Do One Thing

A function that does one thing well is easy to name, test, and reuse. A function that does three things is hard to name, impossible to test independently, and couples three responsibilities.

The test: Can you describe the function without using "and"? If not, split it.

❌ processOrder(order)
   — validates order
   — calculates total with tax
   — saves to database
   — sends confirmation email

✅ validateOrder(order)        → throws if invalid
   calculateOrderTotal(items) → returns numeric total
   submitOrder(order)         → orchestrates the above

Function size limits:

  • Ideal: 5-15 lines
  • Acceptable: up to 30 lines
  • Needs splitting: 30+ lines
  • Unacceptable: 50+ lines (split immediately)

3. Parameters

  • 0-2 parameters: ideal
  • 3 parameters: acceptable with named/destructured args
  • 4+ parameters: use an options object/struct/dataclass
  • Boolean parameters: almost always a code smell — split into two functions
❌ createUser(name, isAdmin)
✅ createUser(name)  /  createAdmin(name)

❌ sendEmail(to, from, subject, body, cc)
✅ sendEmail(options)   ← options is a structured type

4. Comments: Why, Not What

Good code doesn't need comments to explain WHAT it does. Comments should explain WHY — the non-obvious reasoning, business rules, or constraints.

❌ // Increment counter by one
   counter += 1

❌ // Check if user is admin
   if user.role == "admin"

✅ // Stripe requires amount in cents, not dollars
   amountInCents = round(price * 100)

✅ // FDA regulation 21 CFR Part 11 requires audit trail
   auditLog.record(changeEvent)

✅ // WARNING: This query locks the orders table — avoid during peak hours
   db.execute(batchUpdateQuery)

Delete these comments immediately:

  • // TODO: fix this later — fix it now or create a tracked issue
  • // This is a hack — then don't commit the hack
  • // I don't know why this works — figure it out before shipping
  • Commented-out code — delete it; version control has your history

5. Error Handling

Errors are not edge cases — they're expected behavior. Handle them explicitly.

❌ try { save(order) } catch { log("error") }
   → What error? What happens to the order?

❌ try { processPayment(order) } catch { throw Error("Something went wrong") }
   → Useless to the caller

✅ try {
     processPayment(order)
   } catch InsufficientFundsError:
     return { success: false, code: "INSUFFICIENT_FUNDS", retry: false }
   catch PaymentGatewayError:
     logger.error("Payment gateway failure", { orderId: order.id })
     return { success: false, code: "GATEWAY_ERROR", retry: true }
   catch unknown:
     rethrow  → Unknown errors bubble up

6. Don't Repeat Yourself (DRY) — But Don't Over-Abstract

DRY violation — same logic copy-pasted in 3+ places:

tax1 = price1 * 0.08
tax2 = price2 * 0.08
tax3 = price3 * 0.08
→ Extract: calculateTax(price)

Over-abstraction — premature DRY that couples unrelated things:

❌ handleEntity(type, action, data)  → "universal" handler for everything

Rule of Three: Duplicate once is acceptable. Duplicate twice means extract.

7. Code Organization

                        High-level policy (business logic)
                               │
                               ▼
                     ┌─────────────────────┐
                     │   Domain Layer       │  Pure logic, no I/O
                     │   (models, rules)    │
                     └─────────────────────┘
                               │
                     ┌─────────────────────┐
                     │   Application Layer  │  Orchestrates domain objects
                     │   (use cases)        │
                     └─────────────────────┘
                               │
                     ┌─────────────────────┐
                     │   Infrastructure     │  I/O, databases, APIs
                     │   (adapters)         │
                     └─────────────────────┘
                               │
                        Low-level detail (frameworks, drivers)
  • Dependencies point inward (infrastructure depends on domain, not reverse)
  • Business logic never imports from infrastructure
  • Test domain logic without databases, APIs, or frameworks

Quick Refactoring Checklist

Before committing code, check:

  • Can I understand every function in <10 seconds?
  • Are there any functions >30 lines?
  • Are there any files >200 lines (components) or >300 lines (utilities)?
  • Do all names reveal intent without needing comments?
  • Is there any copy-pasted logic (3+ occurrences)?
  • Are errors handled specifically, not swallowed or genericized?
  • Would a new team member understand this without asking me?

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Audit and improve web accessibility following WCAG 2.1 guidelines. Use when asked to "improve accessibility", "a11y audit", "WCAG compliance", "screen reader support", "keyboard navigation", or "make accessible".

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

RepairYourTech/cfsa-antigravity62026년 8월 16일 업데이트

Structured methodology for adversarial thinking — generating attack scenarios, abuse cases, race conditions, and security edge cases against specs and implementations. Produces spec-level gap items, not code-level fixes.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

RepairYourTech/cfsa-antigravity62026년 8월 16일 업데이트

Orchestrate multiple Antigravity skills through guided workflows for SaaS MVP delivery, security audits, AI agent builds, and browser QA.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

RepairYourTech/cfsa-antigravity62026년 8월 16일 업데이트

Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

RepairYourTech/cfsa-antigravity62026년 8월 16일 업데이트

Manage API versioning and evolution with URL/header/query strategies, deprecation workflows, breaking change classification, sunset headers, and consumer-driven contract testing. Use when designing versioning strategy, deprecating endpoints, or evolving API contracts.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

RepairYourTech/cfsa-antigravity62026년 8월 16일 업데이트

Analyzes codebase structure, data flow, module relationships, and key patterns to generate and maintain a living architecture document (ARCHITECTURE.md).

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

RepairYourTech/cfsa-antigravity62026년 8월 16일 업데이트

RepairYourTech의 스킬 모두 보기

이 스킬의 문제 신고