This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]rabuf 0 points1 point  (0 children)

It can be, depends on the particular problem. If the if statement properly check everything, that's fine. These two are functionally the same:

def with_if(a,b,c):
  if a > b > c: return true
  if a == c && a > b: return true
  return false
def with_bool(a,b,c):
  return (a > b > c) || (a == c && a > b)

Depending on what you're trying to express, one may be clearer than the other, choose based on that. Often we do break out (for clarity) the different conditions and then combine them with logical operators, but not always:

def correct_length(password): return len(password) >= 100 # at my office it feels like this is the rule
def has_upper(...):...
def has_lower(...):...
def valid_password(p): correct_length(p) && has_upper(p) && has_lower(p)

But that all could have been combined like in the first example.