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.
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:
array instead of xs, whitespaceCharacters instead of charactersshouldCache for booleans instead of cache, clonedNode instead of clone (which sounds like a function)createCachedSearchFunction instead of the too-generic createCachedFunction, isPrevNodeMarkdownlintComment instead of isPrevNodeSpecificCommentsplitByContinuousWhitespace instead of just splitExample 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.
Enter the URL of a public GitHub repository