Single Purpose Variables

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

43 stars 26 forksSoftware Development

Install

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add obra/clank --skill Single Purpose Variables
Manual install
git clone --depth 1 https://github.com/obra/clank.git /tmp/clank
mkdir -p ~/.claude/skills
cp -r /tmp/clank/skills/coding/single-purpose-variables ~/.claude/skills/Single-Purpose-Variables

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the 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):**
```python
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:**
```python
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:**
```python
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:**
Read the full skill on GitHub

Details

Skill name
Single Purpose Variables
Repository
obra/clank
Path
skills/coding/single-purpose-variables/SKILL.md
Repo updated
9 October 2025

FAQ

What does the Single Purpose Variables skill do?

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

How do I install the Single Purpose Variables skill?

skills CLI (Claude Code, Cursor, Codex and more): npx skills add obra/clank --skill Single Purpose Variables. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Single Purpose Variables popular?

It lives in obra/clank, which has 43 GitHub stars and 26 forks.

Related skills

Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.