Rule
Make a function's purpose self-evident.
Function names should clearly communicate what the function
does without requiring readers to examine the implementation.
Supported languages: 45+Introduction
Function names that don't reveal their purpose force developers to read the entire implementation to understand behavior. A function named process() or handle() could do anything, requiring mental effort to deduce its actual purpose. Clear, descriptive names like validateUserEmail() or calculateOrderTotal() communicate intent immediately, making code self-documenting.
Why it matters
Code maintainability: Unclear function names slow down comprehension. Developers waste time reading implementations to understand what functions do instead of focusing on business logic. This compounds when returning to code months later or when new team members join.
Incorrect usage: Ambiguous function names increase the chance of misuse. A function named update() might validate, transform, persist, or notify, leading developers to use it incorrectly because the name doesn't specify behavior. Clear names prevent misuse by documenting constraints and side effects.
Code examples
❌ Non-compliant:
function process(data) {
const result = data.map(item => ({
...item,
processed: true,
timestamp: Date.now()
}));
db.save(result);
notifyService.send(result);
return result;
}
Why it's wrong: The name process() reveals nothing about what happens to the data. Readers must examine the implementation to learn it transforms items, saves to database, and sends notifications. The function's side effects and responsibilities are hidden.
✅ Compliant:
function markItemsAsProcessedAndSave(data) {
const processedItems = data.map(item => ({
...item,
processed: true,
timestamp: Date.now()
}));
db.save(processedItems);
notifyService.send(processedItems);
return processedItems;
}
Why this matters: The name explicitly states the function marks items as processed and saves them. Readers immediately understand the function's main purpose without reading implementation. The name hints at side effects (saving to database), setting appropriate expectations.
Conclusion
Function names should answer "what does this do?" without requiring code inspection. Include verbs that describe actions and nouns that describe targets. If a name becomes too long, the function likely does too much and should be split.
.avif)
