Choose simpler, more readable code patterns over complex alternatives to improve maintainability and reduce cognitive load. This includes avoiding unnecessary complexity in variable assignment, function parameters, and styling approaches.
Choose simpler, more readable code patterns over complex alternatives to improve maintainability and reduce cognitive load. This includes avoiding unnecessary complexity in variable assignment, function parameters, and styling approaches.
Key practices:
Examples:
Instead of IIFE for complex logic:
const hasAccess = (() => {
if (spec.kind === IntegrationKind.ExternalAuditStorage) {
return hasIntegrationAccess && hasExternalAuditStorage && enabled;
}
return hasIntegrationAccess;
})();
Use simple assignment:
let hasAccess = hasIntegrationAccess;
if (spec.kind === IntegrationKind.ExternalAuditStorage) {
hasAccess &&= hasExternalAuditStorage && enabled;
}
Instead of conditional assignment:
let primaryButtonText = 'Browse Existing Resources';
if (props.primaryButtonText) {
primaryButtonText = props.primaryButtonText;
}
Use destructuring defaults:
export function Finished({
primaryButtonText = 'Browse Existing Resources',
...props
}: Props) {
This approach reduces indentation, eliminates unnecessary complexity, and makes code intent clearer at first glance.
Enter the URL of a public GitHub repository