DEV Community

Discussion on: Else after return: yea or nay?

Collapse
 
sur0g profile image
sur0g

Personally I prefer an implicit else for the most (roughly 90%) cases. For example, we need to return payments info for some user. In that case if we check all unusual states the code looks much more readable. We have all the unusual checks on the topmost and then we implement safe and much cleaner program logic:

def return_payments(user, connection):

    if not user:
        raise UserNotFoundError()

    if not connection:
        raise ConnectionError()

    ...  # actual _safe_ logic goes here