Choose variable, function, and file names that clearly describe their purpose, behavior, and content. Names should be self-documenting and avoid ambiguity about what they represent or do.
Choose variable, function, and file names that clearly describe their purpose, behavior, and content. Names should be self-documenting and avoid ambiguity about what they represent or do.
Key principles:
hasIntersected instead of isIntersecting when the value doesn’t toggle back to false.shared-imports.d.ts over shared.d.ts, or cookieStore over listenCookieChanges to identify the specific API being used.whitelist with allowlist to maintain inclusive terminology.shouldPrefetch() instead of checkShouldPrefetch() when the function returns a boolean indicating whether an action should be performed.Example of good descriptive naming:
// Before: unclear behavior
const isIntersecting = ref(false)
function checkShouldPrefetch() { /* ... */ }
// After: clear and descriptive
const hasIntersected = ref(false)
function shouldPrefetch(): boolean { /* ... */ }
// Before: generic naming
whitelist: string[]
// After: descriptive and inclusive
allowlist: string[]
This approach makes code more maintainable and reduces the need for additional documentation or comments to explain what identifiers represent.
Enter the URL of a public GitHub repository