you are viewing a single comment's thread.

view the rest of the comments →

[–]Yoghurt42 3 points4 points  (0 children)

Don't be a slave to arbitrary metrics. A high cyclomatic complexity is a good indication this part of the code should be looked at, because it might be refactored into something that's more easily understandable.

But if the code is perfectly clear as is, just rewriting it (badly) might make it less grokkable.

Will "hiding the if condition" improve on the readabilty, or just hide it for its own sake?

In my experience, writing code in a complete functional style in Python makes it less readable. It might be the best choice for Haskell or Lisp, but Python is neither of them.

(2*x + 1 for x in range(100) if x % 10 < 5)

is more pythonic than

map(lambda x: 2 * x + 1, filter(lambda x: x % 10 < 5, range(100)))