Prompt
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:
- Reflect actual behavior: Use names that accurately describe what the code does, not just what it might do. For example,
hasIntersectedinstead ofisIntersectingwhen the value doesn’t toggle back to false. - Be specific and clear: Prefer
shared-imports.d.tsovershared.d.ts, orcookieStoreoverlistenCookieChangesto identify the specific API being used. - Use inclusive language: Replace terms like
whitelistwithallowlistto maintain inclusive terminology. - Choose semantic function names: Use
shouldPrefetch()instead ofcheckShouldPrefetch()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.