Use descriptive variable names

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.

copy reviewer prompt

Prompt

Reviewer 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 array instead of xs, whitespaceCharacters instead of characters
  • Indicate type when ambiguous: Use shouldCache for booleans instead of cache, clonedNode instead of clone (which sounds like a function)
  • Be appropriately specific: Use createCachedSearchFunction instead of the too-generic createCachedFunction, isPrevNodeMarkdownlintComment instead of isPrevNodeSpecificComment
  • Include context in method names: Use splitByContinuousWhitespace instead of just split

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.

Source discussions