Write code that prioritizes clarity and simplicity over cleverness. This improves maintainability and reduces cognitive load for other developers. Key practices:
Write code that prioritizes clarity and simplicity over cleverness. This improves maintainability and reduces cognitive load for other developers.
Key practices:
/
operator and or
for conditional assignmentExample of improvements:
# Instead of negative conditional with empty block
if not condition:
pass
else:
do_something()
# Prefer positive conditional
if condition:
do_something()
# Instead of inline complex condition
if not username and not password:
return None
# Extract to named variable for clarity
has_credentials = username or password
if not has_credentials:
return None
# Instead of nameless boolean parameter
return self._handle_install(True)
# Use explicit parameter name
return self._handle_install(with_synchronization=True)
The goal is code that can be understood at a glance without requiring mental gymnastics to parse complex logic or unclear intentions.
Enter the URL of a public GitHub repository