Break down complex code blocks and expressions into simpler, more readable components. Complex boolean logic, nested conditions, and multi-operation lines should be refactored for clarity.
Break down complex code blocks and expressions into simpler, more readable components. Complex boolean logic, nested conditions, and multi-operation lines should be refactored for clarity.
Key practices:
Example - Before:
return unless artifacts.reject do |k|
k.is_a?(::Cask::Artifact::Font)
end.empty?
After:
return if artifacts.all?(::Cask::Artifact::Font)
Or when dealing with complex conditions:
Before:
print_stderr = !(verbose && show_info).nil?
After:
print_stderr = if verbose && show_info
true
else
false
end
This approach makes code easier to read, understand, and maintain while reducing the cognitive load on reviewers and future maintainers.
Enter the URL of a public GitHub repository