Code should include explanatory comments when the purpose, behavior, or context is not immediately clear from reading the code itself. This is especially important for:
Code should include explanatory comments when the purpose, behavior, or context is not immediately clear from reading the code itself. This is especially important for:
Example:
// Before - unclear why early return was removed
if (ngDevMode) {
// ... complex logic
}
// After - explains the reasoning
if (ngDevMode) {
// Note: Early return removed to ensure proper cleanup in all code paths
// ... complex logic
}
// Before - unclear field purpose
export interface ProjectedSignalNode {
propertyNode: ReactiveNode | undefined;
lastProperty: PropertyKey | undefined;
}
// After - explains field usage
export interface ProjectedSignalNode {
// Only used when the projectedSignal key argument is reactive
propertyNode: ReactiveNode | undefined;
// Tracks the last accessed property for change detection
lastProperty: PropertyKey | undefined;
}
Comments should focus on the “why” rather than the “what” - explaining the reasoning, constraints, or important context that future developers need to understand when modifying or using the code.
Enter the URL of a public GitHub repository