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

Single Purpose Variables

Use each variable for exactly one purpose - no hybrid coupling or hidden meanings

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

설치 방법 보기

포함된 파일(1)

  • SKILL.md4.4 KB

SKILL.md(원문)

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

Single Purpose Variables

Overview

Each variable should represent exactly ONE thing. No reusing for different purposes. No hidden meanings.

Core principle: If variable represents count sometimes and error other times, use two variables.

Baseline Violation: Hybrid Coupling

From baseline, agents use special values to indicate errors:

❌ Hybrid coupling (baseline):

def process_file_pages(filename):
    try:
        pages_processed = 0  # Count (integer purpose)
        # ... processing ...
        return pages_processed
    except:
        return -1  # Error flag (boolean purpose as -1)

Problem: pages_processed represents TWO things:

  • Non-negative integer = page count
  • -1 = error occurred

This is hybrid coupling: Variable moonlights as different type.

✅ Separate concerns:

def process_file_pages(filename):
    try:
        pages_processed = 0
        # ... processing ...
        return (True, pages_processed)  # Success, count
    except Exception as e:
        return (False, str(e))  # Failure, error message

Or raise exception:

def process_file_pages(filename):
    # Let exceptions propagate - no hybrid variable needed
    pages_processed = 0
    # ... processing (raises on error) ...
    return pages_processed  # Always a count, never an error

Common Hidden Meanings

❌ What agents naturally do:

page_count = 15  # Number of pages
page_count = -1  # Wait, now it means error!

customer_id = 1234  # Customer number
customer_id = 500001  # Wait, > 500000 means delinquent (subtract 500000)!

bytes_written = 1024  # Bytes written
bytes_written = -5  # Wait, negative means disk drive number!

✅ Separate variables:

page_count = 15
processing_failed = True  # Separate boolean for error state

customer_id = 1234
is_delinquent = False  # Separate boolean for status

bytes_written = 1024
disk_drive = 5  # Separate variable for drive number

Legitimate Variable Reuse

Good reuse (same purpose, same meaning):

# ✅ GOOD: total_sales used for multiple related calculations
total_sales = sum(sales)
average = total_sales / len(sales)  # Same value, same meaning
percentage = (total_sales / target) * 100  # Same value, same meaning

Bad reuse (different purposes):

# ❌ BAD: temp reused for unrelated purposes
temp = sqrt(b*b - 4*a*c)  # Discriminant
root1 = (-b + temp) / (2*a)
# ...
temp = root1  # Now reused for swapping (different purpose!)
root1 = root2
root2 = temp

✅ Separate variables:

discriminant = sqrt(b*b - 4*a*c)  # Clear purpose
root1 = (-b + discriminant) / (2*a)
# ...
old_root = root1  # Clear purpose (swapping)
root1 = root2
root2 = old_root

Quick Reference

ViolationExampleFix
Hybrid couplingcount=-1 means errorSeparate: count + error_occurred boolean
Hidden meaningsid > 500000 means delinquentSeparate: id + is_delinquent
Temp reusetemp for discriminant, then swappingUse: discriminant, old_root
State changesVariable means X, then means YTwo variables with clear names

Red Flags

  • Variable represents different types (integer sometimes, boolean as -1)
  • Special values have hidden meanings (-1, 0, null mean different things)
  • Reusing temp, result, value for unrelated purposes
  • Code comments explain "if X then it means Y, else Z"
  • Must remember what value currently means

Fix: Create separate variable with clear name for each purpose.

Real-World Impact

From Code Complete:

  • Hybrid coupling creates confusion
  • Even if clear to you, won't be to others
  • Extra variable costs nothing, clarity is priceless

From baseline:

  • Agent used -1 to indicate error in count variable (hybrid coupling)

With this skill: Separate variables for separate purposes.

Integration with Other Skills

For naming clarity: See skills/naming-variables - each purpose needs its own well-named variable

리뷰

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

댓글

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

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

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

0 / 1,000자

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

같은 저장소의 스킬

Interactive idea refinement using Socratic method to develop fully-formed designs

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

obra/clank422025년 10월 10일 업데이트

Receive and act on code review feedback with technical rigor, not performative agreement or blind implementation

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

obra/clank422025년 10월 10일 업데이트

Comment WHY code exists and non-obvious decisions, not WHAT code does (mechanics)

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

obra/clank422025년 10월 10일 업데이트

Replace arbitrary timeouts with condition polling for reliable async tests

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

obra/clank422025년 10월 10일 업데이트

TDD for process documentation - test with subagents before writing, iterate until bulletproof

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

obra/clank422025년 10월 10일 업데이트

Validate at every layer data passes through to make bugs impossible

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

obra/clank422025년 10월 10일 업데이트

obra의 스킬 모두 보기

이 스킬의 문제 신고