DEV Community

Lorenzo Tinfena
Lorenzo Tinfena

Posted on

2 2

If else return break best practices

Do not write:

func () {
    if (something)
        return true;
    return false;
}
Enter fullscreen mode Exit fullscreen mode

Instead write:

func () {
    if (something)
        return true;
    else
        return false;
}
Enter fullscreen mode Exit fullscreen mode

Do not write:

func () {
    while (somehing)
        if (somethingelse)
            break;

}
Enter fullscreen mode Exit fullscreen mode

Instead write:

func () {
    while (somehing)
        if (somethingelse)
            return;
}
Enter fullscreen mode Exit fullscreen mode

These are my current best practices, what do you think?

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay