{"success":true,"name":"replace-magic-numbers-with-named-constants","description":"Code contains bare numbers or strings whose meaning isn't obvious.","category":"ai-brimind","path":"ai-brimind/replace-magic-numbers-with-named-constants/SKILL.md","file":"SKILL.md","content":"---\nname: replace-magic-numbers-with-named-constants\ndescription: \"Code contains bare numbers or strings whose meaning isn't obvious.\"\n---\n\n# Replace Magic Numbers With Named Constants\n\n## When to use\nLiterals like 86400, 3, 0.19, or 'type2' appear directly in logic, and their meaning or reason lives only in the author's memory.\n\n## Example request\nif (items.length > 25) scattered in four places → the limit changes to 50 and one spot is missed — duplicated unnamed threshold. setTimeout(x, 86400000) → the reader must compute that's 24 hours — meaning hidden in arithmetic. status === 2 → what is 2? The mapping lives in someone's head or another system — undocumented code value.\n\n## Instructions\nAct like a developer who makes every number explain itself. When a bare literal appears in logic: (1) ask what it MEANS — if the answer isn't instant to a stranger, extract it to a named constant: MAX_ITEMS_PER_PAGE = 25, ONE_DAY_MS = 24 * 60 * 60 * 1000 (show the derivation; it documents itself), VAT_RATE = 0.19; (2) if the same value appears in multiple places BECAUSE it's the same rule, one constant is now the single point of change — but don't merge coincidentally-equal numbers that represent different rules; they must be able to diverge; (3) for code values from external systems (status === 2), define a mapping object or enum-like constant (STATUS.ACTIVE = 2) so the domain word appears in logic, not the raw code; (4) obvious cases stay literal — 0, 1, array indices in trivial loops don't need ceremony. The test: could someone change this value confidently without reading the whole file? Only proceed once every non-obvious literal has a name stating its meaning and, where useful, a comment stating its source.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1105\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}