If else return break best practices

Lorenzo Tinfena
Mar 29, 2022

--

Do not write:

func () {
if (something)
return true;
return false;
}

Instead write:

func () {
if (something)
return true;
else
return false;
}

Do not write:

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

Instead write:

func () {
while (somehing)
if (somethingelse)
return;
}

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

--

--

Lorenzo Tinfena
Lorenzo Tinfena

Written by Lorenzo Tinfena

Computer science student - Artificial intelligence enthusiast. https://github.com/lorenzotinfena

No responses yet