Skip to content

Defensive Naming

Medium — good to knowGeneral Dev

ELI5 - The Vibe Check

You don't just call it 'data,' you call it 'rawUserInputUnvalidated' because you know, deep in your bones, that someone, possibly future you, will eventually use it without checking it first. Defensive naming is writing variable and function names so explicit about their risks and assumptions that misuse becomes almost impossible, even for someone skimming at 2 a.m.

Real Talk

Defensive naming is the practice of choosing identifiers that make a value's state, safety, or assumptions explicit, such as raw versus sanitized or validated versus unvalidated, so that misuse is caught by inspection rather than by a runtime bug. It trades a small amount of verbosity for a meaningful reduction in the class of errors that come from developers assuming more than a name actually guarantees.

When You'll Hear This

"Rename it to rawInput, defensive naming would have caught this bug in code review." / "I know it's verbose, but defensive naming has saved us from this exact mistake before."

Made with passive-aggressive love by manoga.digital. Powered by Claude.