Why this matters
Overly defensive programming that handles unrealistic scenarios increases code complexity. Focus on handling real-world edge cases instead.
Identify overly defensive code that checks for unrealistic conditions, such as excessive nil? checks or redundant type verifications.
Overly defensive programming that handles unrealistic scenarios increases code complexity. Focus on handling real-world edge cases instead.
Side-by-side examples engineers can pattern-match during review.
def process(input)
if input.nil? || !input.is_a?(String) || input.empty?
return "Invalid input"
end
input.strip.upcase
end
def process(input)
return unless input.is_a?(String) && !input.empty?
input.strip.upcase
end
From the same buckets as this rule.