Exploring alternatives

From obra/clank · View interactive version

Exploring alternatives is an AI agent skill from the GitHub repository obra/clank. Try 2-3 different approaches before implementing - don't settle for first design you think of

How to use this skill

Skill file

Exploring Alternatives

Overview

Don't settle for the first design you think of. Try multiple approaches, compare trade-offs, pick the best, THEN implement.

Core principle: Design is cheap to iterate. Code is expensive. Once you write code, emotional attachment makes it hard to throw away. Explore alternatives while iteration is still cheap.

Violating the letter of this rule is violating the spirit of good design.

When to Use

Always use before implementing:

Especially when:

Warning signs you need this:

The Exploration Process

Step 1: Understand the Problem

Before exploring solutions, clarify the problem:

If problem is unclear, exploring solutions is premature.

Step 2: Generate 2-3 Alternatives

Don't stop at first idea. Generate at least 2 more.

Techniques for generating alternatives:

  1. Different data structures:
  1. Different algorithms:
  1. Different levels of abstraction:
  1. Different responsibility allocation:
  1. Different error handling:

For each approach, sketch it in pseudocode or bullet points.

Step 3: Compare Trade-offs

Evaluate each alternative against criteria:

| Criterion | Alternative 1 | Alternative 2 | Alternative 3 |

|-----------|---------------|---------------|---------------|

| Simplicity | Simple | Complex | Medium |

| Performance | Fast | Slow | Medium |

| Maintainability | Easy to modify | Hard to change | Medium |

| Testability | Easy to test | Hard to test | Medium |

| Flexibility | Rigid | Very flexible | Some flex |

| Development time | Quick | Slow | Medium |

Which criteria matter most for this problem?

Step 4: Pick the Best

Choose based on:

Document why you picked it:

Step 5: Implement

Only after comparing alternatives, implement the chosen approach.

If implementation fights you → return to Step 2. You might have picked wrong alternative.

Quick Reference

| When | What to Explore | Example Alternatives |

|------|-----------------|----------------------|

| Data structure choice | Different structures | Array, LinkedList, HashMap, Tree |

| Algorithm choice | Different algorithms | Iterative, Recursive, Different approach |

| Error handling | Different strategies | Exceptions, Return codes, Defaults |

| Responsibility | Different decompositions | One class, Multiple classes, Functions |

| Abstraction level | Build vs use | Custom implementation, Library, Framework |

| Complexity trade-off | Simple vs flexible | Specific solution, Generic solution |

Example: Validation Function

Problem: Validate user registration data

Alternative 1: Manual Validation

def validate_registration(data: dict) -> tuple[bool, str]:
    if 'email' not in data:
        return False, "Missing email"
    if not re.match(email_pattern, data['email']):
        return False, "Invalid email"
    # ... validate each field manually

Trade-offs:

Alternative 2: Pydantic Model

from pydantic import BaseModel, EmailStr, Field

class RegistrationData(BaseModel):
    email: EmailStr
    password: str = Field(min_length=8)
    username: str
    age: int = Field(ge=18)

def validate_registration(data: dict) -> tuple[bool, str]:
    try:
        RegistrationData(**data)
        return True, ""
    except ValidationError as e:
        return False, str(e)

Trade-offs:

Alternative 3: Validator Class

class RegistrationValidator:
    def __init__(self, data):
        self.data = data
        self.errors = []

    def validate(self):
        self._validate_email()
        self._validate_password()
        self._validate_username()
        self._validate_age()
        return len(self.errors) == 0, ", ".join(self.errors)

    def _validate_email(self):
        # Focused validation method

Trade-offs:

Comparison

For this problem:

By exploring all three, you make informed decision instead of defaulting to first idea.

Common Mistakes

❌ Implementing first idea:

Think of approach → implement immediately → discover problems → hack fixes

✅ Exploring alternatives:

Think of approach → sketch it → think of alternative → sketch it → compare → pick best → implement cleanly

❌ "This is obviously the best way":

Without exploring, you don't know if it's best. Your "obvious" solution might be suboptimal.

✅ "Let me try two other approaches to confirm this is best":

Even if first idea wins, exploring validates your choice.


❌ Exploring in code:

Writing full implementations of multiple approaches wastes time and creates emotional attachment.

✅ Exploring in pseudocode/sketches:

Quick, cheap, easy to discard.

If You Already Implemented First Idea

You implemented without exploring alternatives. Now what?

No exceptions:

Required steps:

  1. Acknowledge the sunk cost - Hours spent are already gone
  2. Sketch 2 alternatives - Don't look at your implementation while sketching
  3. Include current implementation as Alternative 1 - Describe what it does
  4. Compare all 3 honestly - Is your implementation actually the best?
  5. Decide:

This isn't punishment. It's good engineering.

Working code that's not the best approach = technical debt. Pay it now or pay interest later.

Time investment:

9 minutes now vs hours of maintenance later.

Red Flags - STOP and Explore

Before implementing:

During implementing:

All of these mean: Stop. Explore alternatives in pseudocode.

Common Rationalizations

| Excuse | Reality |

|--------|---------|

| "First idea is obviously best" | Without exploring, you don't know. Try 2 more anyway. |

| "Don't want to waste time" | 5 minutes exploring saves hours of bad implementation. |

| "This approach already works" | Working ≠ best. Other approaches might be simpler. |

| "I'm experienced, I know the right approach" | Experience creates bias. Check your intuition. |

| "Problem is too simple to need alternatives" | Even simple problems benefit. Takes 2 minutes. |

| "Already started coding, too late" | Sunk cost fallacy. Still cheaper to explore now than debug later. |

| "Other approaches won't work" | How do you know without trying them? |

Verification Checklist

Before marking design complete:

Can't check all boxes? Return to Step 2 (generate alternatives).

When to Stop Exploring

Explore 2-3 alternatives minimum. Stop when:

  1. Clear winner emerges - One approach obviously superior for your criteria
  2. Diminishing returns - Alternative 4 and 5 aren't meaningfully different
  3. Good enough found - Approach meets requirements simply and clearly

Don't:

Balance: Enough exploration to find good solutions, not so much you never implement.

Quick Exploration Template

## Problem
[State the problem clearly]

## Alternative 1: [Name]
[Sketch the approach]
Pros: ...
Cons: ...

## Alternative 2: [Name]
[Sketch the approach]
Pros: ...
Cons: ...

## Alternative 3: [Name]
[Sketch the approach]
Pros: ...
Cons: ...

## Decision
Chose [Alternative X] because [reasoning based on requirements and trade-offs]

Use this template when designing non-trivial solutions.

Real-World Impact

From Code Complete:

From baseline testing:

With this skill: Systematic exploration before implementation.

Integration with Other Skills

For design iteration: See skills/designing-before-coding - exploring alternatives happens during the pseudocode phase (Step 7)

For complexity: See skills/architecture/reducing-complexity - simpler alternatives reduce complexity

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.