Why this matters
Lambdas are useful for short, simple functions, but complex ones can be harder to read and debug. Use titled functions when more clarity is needed.
Identify lambda functions that are too complex. Lambdas should be simple and concise. If a lambda contains multiple expressions, recommend converting it to a titled function for better readability.
Lambdas are useful for short, simple functions, but complex ones can be harder to read and debug. Use titled functions when more clarity is needed.
Side-by-side examples engineers can pattern-match during review.
items.sort(key=lambda x: x[0] * x[1] - x[2] ** 2)def custom_sort_key(item):
return item[0] * item[1] - item[2] ** 2
items.sort(key=custom_sort_key)items.sort(key=lambda x: x[0] * x[1] - x[2] ** 2)def custom_sort_key(item):
return item[0] * item[1] - item[2] ** 2
items.sort(key=custom_sort_key)From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.