{
    "slug": "yagni",
    "term": "YAGNI",
    "category": "quality",
    "difficulty": "beginner",
    "short": "You Aren't Gonna Need It — don't implement functionality until it's actually required.",
    "long": "YAGNI is an Extreme Programming principle arguing that developers should not add functionality based on speculation about future needs. Premature generalisation creates dead code, complicates maintenance, and often builds the wrong abstraction — requirements change and the speculative feature is never used or is removed. Implement the simplest thing that works for current requirements. Refactor to accommodate new requirements when they actually arrive — by then you'll have more information to design correctly.",
    "aliases": [
        "You Aren't Gonna Need It",
        "YAGNI principle",
        "no speculative features"
    ],
    "tags": [
        "principles",
        "agile",
        "quality",
        "xp"
    ],
    "misconception": "YAGNI means writing the minimum code possible and never thinking ahead. It means not building features until they are actually required — thinking ahead about architecture and extensibility is still valuable; building unasked-for features is what YAGNI discourages.",
    "why_it_matters": "You Aren't Gonna Need It prevents speculative complexity — every abstraction that turns out to be wrong adds maintenance cost without ever delivering value, and the code that isn't written can't have bugs.",
    "common_mistakes": [
        "Designing plugin systems, configuration layers, or factory hierarchies for a single use case.",
        "Adding method parameters for 'future options' that never materialise.",
        "Implementing multiple output formats (JSON, XML, CSV) when only JSON is currently needed.",
        "Confusing YAGNI with not writing tests — tests for current requirements are not speculative."
    ],
    "when_to_use": [
        "Feature development — do not build configurability, plugins, or extension points until a real need exists.",
        "Abstractions — do not create interfaces or base classes for a single implementation that may never have a second.",
        "Performance optimisation — do not optimise before profiling shows an actual bottleneck.",
        "Resisting stakeholder requests to 'just add a flag for that' — every flag is future complexity."
    ],
    "avoid_when": [
        "Core infrastructure decisions (database schema, API contracts, auth) where retrofitting is expensive — some upfront design is justified.",
        "Security — do not defer input validation, auth checks, or encryption on the grounds that attacks may not happen.",
        "Accessibility and internationalisation in consumer products — retrofitting is far more expensive than building in from the start."
    ],
    "related": [
        "speculative_generality",
        "dry",
        "technical_debt"
    ],
    "prerequisites": [
        "kiss_principle",
        "dry",
        "speculative_generality"
    ],
    "refs": [
        "https://martinfowler.com/bliki/Yagni.html"
    ],
    "bad_code": "class UserRepository {\n    // Built 'just in case' — never called\n    public function findByAstrologicalSign(string $sign): array { ... }\n    public function exportToExcel(): string { ... }\n    public function importFromLegacyCsv(): void { ... }\n}",
    "good_code": "class UserRepository {\n    public function findById(int $id): ?User { ... }\n    public function findByEmail(string $email): ?User { ... }\n    public function save(User $user): void { ... }\n    // Add methods when a real feature requires them\n}",
    "quick_fix": "Delete the feature/abstraction/flexibility that no current requirement needs — if it is needed later, add it then with full context",
    "severity": "info",
    "effort": "low",
    "created": "2026-03-15",
    "updated": "2026-03-25",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/yagni",
        "html_url": "https://codeclaritylab.com/glossary/yagni",
        "json_url": "https://codeclaritylab.com/glossary/yagni.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[YAGNI](https://codeclaritylab.com/glossary/yagni) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/yagni"
            }
        }
    }
}