Write code that optimizes for human readability and understanding. Complex expressions, while technically correct, can become difficult to understand and maintain over time.
Write code that optimizes for human readability and understanding. Complex expressions, while technically correct, can become difficult to understand and maintain over time.
When facing complex logic, prefer explicit, step-by-step approaches over condensed one-liners. This applies particularly to nested expressions, complex conditionals, and list comprehensions.
For example, instead of:
klass = next(
(c for cond, c in COMPLIANCE_CLASS_MAP.get(provider_type, []) if cond(name)),
GenericCompliance,
)
Consider a more readable approach:
klass = GenericCompliance # Default value
for condition, cls in COMPLIANCE_CLASS_MAP.get(provider_type, []):
if condition(name):
klass = cls
break
Other readability practices to follow:
get_
functions should return values, not modify state)Remember that code is read many more times than it’s written. Optimizing for readability leads to fewer bugs and easier maintenance.
Enter the URL of a public GitHub repository