DEV Community

Discussion on: Else after return: yea or nay?

Collapse
 
qm3ster profile image
Mihail Malo

A ternary would make even more sense than explicit else in the last case:

def check_link(link) -> bool:
    return if is_internal_link(link) {
            check_internal_link(link)
        } else {
            check_external_link(link)
        }
def check_link(link) -> bool:
    return is_internal_link(link)
        ? check_internal_link(link)
        : check_external_link(link)

Unfortunately, python ternary looks like this:

def check_link(link) -> bool:
    return check_internal_link(link) if is_internal_link(link) else check_external_link(link)

how do you even format this?

def check_link(link) -> bool:
    return check_internal_link(link)
        if is_internal_link(link) # this is the condition for the above lol
        else check_external_link(link)
Collapse
 
dmerejkowsky profile image
Dimitri Merejkowsky

Yeah. As a rule I avoid ternary stuff in Python.

But this is a topic for an other discussion ;)

Collapse
 
qm3ster profile image
Mihail Malo

Don't see you in the comments there, whereas I have already laid my 💩posting.