Names should accurately reflect the actual behavior, constraints, and purpose of the code element they represent. Misleading names create confusion and make code harder to understand and maintain.
Names should accurately reflect the actual behavior, constraints, and purpose of the code element they represent. Misleading names create confusion and make code harder to understand and maintain.
Key principles:
RequiredOptions
if it contains optional properties)Example of problematic naming:
// Misleading - contains optional properties despite "Required" in name
export interface RequiredOptions {
singleAttributePerLine: boolean;
jsxBracketSameLine?: boolean; // Optional property in "Required" interface
}
Better approach:
// Clear and accurate naming
export interface FormattingOptions {
singleAttributePerLine: boolean;
jsxBracketSameLine?: boolean;
}
// Or separate required vs optional
export interface RequiredFormattingOptions {
singleAttributePerLine: boolean;
}
export interface OptionalFormattingOptions {
jsxBracketSameLine?: boolean;
}
When reviewing code, ask: “Does this name accurately describe what this element actually does or contains?” Names that contradict their implementation create technical debt and developer confusion.
Enter the URL of a public GitHub repository