Choose straightforward, readable code patterns over complex or clever alternatives. This improves maintainability and reduces cognitive load for other developers.
Choose straightforward, readable code patterns over complex or clever alternatives. This improves maintainability and reduces cognitive load for other developers.
Key principles:
array.some(condition)
instead of array.find(condition) !== null
value && expression
instead of value ? expression : null
when appropriateswitch
statements instead of mapping objects when the logic is clearerExample:
// Complex/clever approach
const result = items.find(item => item.active) !== null ? processItems() : null;
const status = flags & DIRTY_FLAG !== 0 ? 1 : 0;
// Simple, readable approach
const hasActiveItem = items.some(item => item.active);
if (hasActiveItem) {
processItems();
}
const isDirty = (flags & DIRTY_FLAG) !== 0;
The goal is code that can be quickly understood by any team member, even when they’re unfamiliar with the specific context or under time pressure.
Enter the URL of a public GitHub repository