{"success":true,"name":"keep-functions-small-enough-to-hold-in-your-head","description":"A function has grown long, deeply nested, or does several jobs.","category":"ai-brimind","path":"ai-brimind/keep-functions-small-enough-to-hold-in-your-head/SKILL.md","file":"SKILL.md","content":"---\nname: keep-functions-small-enough-to-hold-in-your-head\ndescription: \"A function has grown long, deeply nested, or does several jobs.\"\n---\n\n# Keep Functions Small Enough to Hold in Your Head\n\n## When to use\nYou are writing or editing a function that scrolls past a screen, nests 4+ levels deep, or whose description needs the word 'and' more than once.\n\n## Example request\n200-line function validating, transforming, saving, and emailing → a bug in step 2 requires understanding all four — tangled responsibilities. Six levels of nested ifs → nobody can track which conditions are active at the bottom — arrow anti-pattern; early returns flatten it. 'Small fix' inside a giant function breaks an unrelated branch → shared variables couple distant parts — hidden coupling in one scope.\n\n## Instructions\nAct like a developer who sizes functions by comprehension, not by line-count rules. Signals a function needs splitting: describing it requires multiple 'and's; you scroll to see all of it; variables from the top are still alive 100 lines later; testing one part requires setting up all parts. How to split: (1) extract each named step into its own function whose name IS the comment ('validateOrderInput', 'applyDiscounts') — the parent becomes a readable table of contents of calls; (2) flatten nesting with guard clauses — handle the error/empty cases with early returns at the top, so the main logic sits at one indentation level instead of inside four ifs; (3) watch the seams: if an extracted piece needs eight parameters, the split is at the wrong line — good seams pass little; (4) don't over-split into confetti either — a coherent 30-line function beats six 5-line fragments that force jumping around. The test: can a junior read the parent function alone and correctly say what happens in what order? Only proceed when yes.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1107\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}