Code Style - Do you prefer to return from a function early or just use an IF statement?
- by Rachel
I've often written this sort of function in both formats, and I was wondering if one format is preferred over another, and why.
public void SomeFunction(bool someCondition)
{
if (someCondition)
{
// Do Something
}
}
or
public void SomeFunction(bool someCondition)
{
if (!someCondition)
return;
// Do Something
}
I usually code with the first one since that is the way my brain works while coding, although I think I prefer the 2nd one since it takes care of any error handling right away and I find it easier to read