Prompt
Choose variable, function, and export names that clearly communicate their purpose and content. Avoid abbreviations and ambiguous terms that could mislead other developers about what the identifier represents.
Key principles:
- Variable names should accurately reflect what they contain, not just their general category
- Avoid abbreviations when full words improve clarity (e.g.,
previousCounterinstead ofprevCounter) - Export names should be specific enough to understand their purpose (e.g.,
ProgressBarinstead ofBar)
Example of unclear naming:
const subProcess = childProcess.spawn('ping', ['8.8.8.8']).stdout;
// Misleading: subProcess actually contains stdout, not the process
exports.Bar = Bar; // Too ambiguous
Example of clear naming:
const subProcess = childProcess.spawn('ping', ['8.8.8.8']);
const stdout = subProcess.stdout;
// Clear: each variable accurately represents what it contains
exports.ProgressBar = ProgressBar; // Specific and clear
This practice prevents confusion during code reviews and maintenance, making the codebase more self-documenting and easier to understand.