Prompt
Choose variable and function names that clearly communicate their purpose, type, and context. Avoid abbreviations, overly generic terms, and names that could be confused for different types.
Key principles:
- Communicate intent: Use
arrayinstead ofxs,whitespaceCharactersinstead ofcharacters - Indicate type when ambiguous: Use
shouldCachefor booleans instead ofcache,clonedNodeinstead ofclone(which sounds like a function) - Be appropriately specific: Use
createCachedSearchFunctioninstead of the too-genericcreateCachedFunction,isPrevNodeMarkdownlintCommentinstead ofisPrevNodeSpecificComment - Include context in method names: Use
splitByContinuousWhitespaceinstead of justsplit
Example improvements:
// Before: unclear and generic
function chunk(xs, chunkSize) { ... }
const cache = new Map();
function createCachedFunction(function_) { ... }
// After: descriptive and clear
function chunk(array, size) { ... }
const shouldCache = true;
function createCachedSearchFunction(searchFunction) { ... }
This approach makes code self-documenting and reduces the cognitive load for other developers reading and maintaining the code.