If else return break best practices

lorenzotinfena

Lorenzo Tinfena

Posted on December 7, 2021

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?

💖 💪 🙅 🚩
lorenzotinfena
Lorenzo Tinfena

Posted on December 7, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related