Don't use flags in functions


Python Clean Code Tip:

Don't use flags in functions.

Flags are variables passed to functions, which the function uses to determine its behavior. This pattern should be avoided since functions should only perform a single task. If you find yourself doing this, split your function into smaller functions.

👇

text = "This is a cool blog post"

# This is bad
def transform(text, uppercase):
    if uppercase:
        return text.upper()
    else:
        return text.lower()


# This is good
def uppercase(text):
    return text.upper()


def lowercase(text):
    return text.lower()