DEV Community

Lorenzo Tinfena
Lorenzo Tinfena

Posted on

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)